|
-
Aug 21st, 2009, 09:50 AM
#1
Thread Starter
Member
[RESOLVED] File name generator
Hi, im working for a school project and im trying to make a screenshot tool
so i made it very simple with the following code below
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim ScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenGrab)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), ScreenSize)
screenGrab.Save("C:\Screen.jpeg")
MsgBox("Screenshot has been succesfully made!", MsgBoxStyle.Information, "Screenshot Success!")
Catch ex As Exception
MsgBox("Error", MsgBoxStyle.Critical, "Error!")
End Try
End Sub
End Class
so as you can see in my form only exists one button that takes the screenshot and then saves it in C:\ directory with the name SCREEN.JPEG
but here's the problem i want to make it whenever i click the BUTTON to take the screeshot to generate a new name for the new screenshot (e.g. screen2.jpeg and so on and on...). I just want to not overwrite the first screenshot but to generate another name for the second screenshot.
I'm sorry for my bad english...
i would appreciate your help
p.s
i forgot to mention, I'm using Visual Basic 2008 Express Edition
-
Aug 21st, 2009, 09:59 AM
#2
Re: File name generator
Why don't you use unique names such as
vb Code:
Dim strFilename As String
strFilename = Format(Now, "ddmmyyyyhhmmss")
MsgBox strFilename & ".Jpeg"
BTW is this vb.net? You might have to change it to vb.net code...
Last edited by Siddharth Rout; Aug 21st, 2009 at 10:02 AM.
Reason: Typo
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Aug 21st, 2009, 10:14 AM
#3
Re: File name generator
try this:
'from vbwire 11-19-08 if the filname exists it appends a number to the filename
Code:
Public Function GetUniqueFileName(ByVal FileName As String) As String
Dim uniqueID As Long
Dim sFile As String
Dim sExt As Long, iExt As Integer
sFile = Dir$(FileName, vbArchive)
If sFile = vbNullString Then
GetUniqueFileName = FileName
Else
iExt = InStrRev(FileName, ".")
If iExt = 0 Then
FileName = FileName & "[#]"
Else
FileName = Left$(FileName, iExt - 1) & "[#]" & Mid$(FileName, iExt)
End If
Do
uniqueID = uniqueID + 1
sFile = Dir$(Replace$(FileName, "#", uniqueID), vbArchive)
Loop Until sFile = vbNullString
GetUniqueFileName = Replace$(FileName, "#", uniqueID)
End If
End Function
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Aug 21st, 2009, 10:23 AM
#4
Re: File name generator
 Originally Posted by jareck
I'm using Visual Basic 2008 Express Edition
And that is why it should be in Visual Basic .NET rather than Visual Basic 6 And Earlier.
Moved
-
Aug 21st, 2009, 02:32 PM
#5
Re: File name generator
You could always use IO.Path.GetTempFileName() to get a temp file name. Just make sure you clean them up when you are done with them.
-
Aug 22nd, 2009, 04:06 AM
#6
Thread Starter
Member
Re: File name generator
hey thanks for your help everyone
now i see how dump i am
i just could use unique file names as koolsid said
thnx again
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|