Steven_Teo
04-17-2003, 09:34 AM
Hi,
I am able to save data to a file whenever I start my program. The problem is that I need to save the data to a different file instead of always overiding the original file. Is it possible to make a date time stamp in my filename everytime I run my program so that I would not overide my original ... something like: filename_date_time. If that is not possible, is there a way I could save data to a different filename everytime i start my program?? Really need your help on this. Thanks.
Code A
04-17-2003, 09:47 AM
why not just always write to a new file and name the file the filename plus the date?
Steven_Teo
04-17-2003, 11:19 AM
why not just always write to a new file and name the file the filename plus the date?
This is what I'm using:
Dim ff As Integer
ff = FreeFile
Open "yourfile" For Binary As #ff
Put #ff, LOF(ff) + 1, YourData
Close #ff
I got this from the forum .. as you can see, I need to specify my filename. If everytime I start my program, I need to change my filename. That is both troublesome and inefficient. If there is a way to change my filename automatically everytime I start the program, it will save me a lot of trouble. Is there anyone with a similar problem to mine and has solve it?? Thanks.
loquin
04-17-2003, 01:27 PM
OK.
Take a look at the Now() function (F1=Help) - it returns the current Date/Timestamp.
Then, look at the Format Function. It's a very flexible function which is used to convert numbers and date/times to a string, formatted as you specify.
Once you get a date/time formatted as you would like to see it (Probabaly yyyymmddhhmm) you attach (concatenate) this string to your base file name.
Note: this site is not a 'Cut-N-Paste' shop; we don't provide code snippets to order. We will help you out with specific problems, and help with the direction to take to get you started. Work with the functions I mentioned above, & come back with specific questions if/when you run into problems
(FYI; the code you show doesn't replace the file with your data; it appends your data to the end of the file, which is can be a friendlier approach from a maintenence viewpoint than creating an entirely new file every time you run the app.)
Steven_Teo
04-18-2003, 04:43 AM
OK.
Note: this site is not a 'Cut-N-Paste' shop; we don't provide code snippets to order. We will help you out with specific problems, and help with the direction to take to get you started. Work with the functions I mentioned above, & come back with specific questions if/when you run into problems
(FYI; the code you show doesn't replace the file with your data; it appends your data to the end of the file, which is can be a friendlier approach from a maintenence viewpoint than creating an entirely new file every time you run the app.)
Thanks for the help, I will try the functions you mentioned. I will do my best to try out things on my own but sometimes I don't know how and don't know where to start. Just for your info, I'm learning VB from scratch and this is my 2nd week into VB. Thanks again, will come back if I encounter more problems.
use something like this. this gives u a unique file every second
Dim ff As Integer
Dim myfile As String
myfile = "C:\LastOpened" & Format(Now, "ddmmyyyyhhmmss") & ".txt"
MsgBox myfile
ff = FreeFile
Open myfile For Binary As #ff
'Put #ff, LOF(ff) + 1, "mydata"
Close #ff