|
-
Jul 10th, 2006, 02:02 PM
#1
Thread Starter
New Member
[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
-
Jul 10th, 2006, 02:10 PM
#2
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
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 10th, 2006, 02:13 PM
#3
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
-
Jul 10th, 2006, 02:21 PM
#4
Thread Starter
New Member
Re: Saving file with date and time on the name
Thanks a lot!! It worked perfect!
I´ll work on my coding
Etamayo
-
Jul 10th, 2006, 03:58 PM
#5
Re: Saving file with date and time on the name
 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
-
Jul 11th, 2006, 12:01 AM
#6
Re: Saving file with date and time on the name
 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
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
|