[RESOLVED] Saving file with date and time on the name
Hello!
I´ve been trying to save a file with date and time on the name, to be more specific:
I need to take a ScreenShot and then save it to an especific route with the current date and time, this is what I tried:
Private Sub Command2_Click()
Dim Name As String
Name = DateTime.Now
SavePicture Picture1.Picture, "c:\mypic " + Name + ".bmp"
'keybd_event 44, 1, 0&, 0&
End Sub
Any ideas?
Thanks in advance.
Etamayo
Re: Saving file with date and time on the name
first dont use Name (use something like fName)
second dont use + use & when combining strings
VB Code:
Private Sub Command2_Click()
Dim fName As String
fName = Format(Now, "mm_dd_yyyy_hh_mm_ss_am/pm")
SavePicture Picture1.Picture, "c:\mypic " & fName & ".bmp"
End Sub
Re: Saving file with date and time on the name
you cannot save a picture in that format because DateTime will result in date seperated by '/' and time by ':' which are not supported by the Win OS as part of file name.
try this:
VB Code:
Private Sub Command1_Click()
Dim name As String
name = DateTime.Now
name = Replace(name, "/", "-")
name = Replace(name, ":", "_")
SavePicture Picture1.Picture, "C:\Documents and Settings\Administrator\Desktop\" + name + ".bmp"
End Sub
Re: Saving file with date and time on the name
Thanks a lot!! It worked perfect!
I´ll work on my coding
Etamayo
Re: Saving file with date and time on the name
Quote:
Originally Posted by Harsh Gupta
you cannot save a picture in that format because DateTime will result in date seperated by '/' and time by ':' which are not supported by the Win OS as part of file name.
Static code is not returning any "/" character. fName = Format(Now, "mm_dd_yyyy_hh_mm_ss_am/pm") will return something like "07_11_2006_02_30_06_am". so he is correct. Anyway Similar way
VB Code:
Private Sub Command2_Click()
SavePicture Picture1.Picture, "c:\mypic " & Format(Now, "mmddyyyyHHmmss") & ".bmp"
End Sub
Re: Saving file with date and time on the name
Quote:
Originally Posted by cssriraman
Static code is not returning any "/" character. fName = Format(Now, "mm_dd_yyyy_hh_mm_ss_am/pm") will return something like "07_11_2006_02_30_06_am". so he is correct. Anyway Similar way
VB Code:
Private Sub Command2_Click()
SavePicture Picture1.Picture, "c:\mypic " & Format(Now, "mmddyyyyHHmmss") & ".bmp"
End Sub
i never said that Static's method wont work. He is using / in the format function to select either AM or PM.
I posted according to the OP's code, that DateTime will return answer with / and : characters which is not acceptable by the OS.
BTW, Static's post was not there when i posted ;)