Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Date Stamp a File
Author | Message | ||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
I want to save files to an SD card. As so.... Open "A:/test/data" For Output As#1 Print #1, x;",";y;",";z Close #1 Then next day I want to save the same files that will have different values. How can I Time Stamp them so they are saved separate to the data the previous day. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
You need a different file name, for example: Open "A:/test/data"+DATE$ For Output As#1 Alternatively, rename the old file before creating the new one: ReName "A:/test/data" as "A:/test/data"+DATE$ Open "A:/test/data" For Output As#1 Geoff Edited 2024-03-04 15:55 by Geoffg Geoff Graham - http://geoffg.net |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
I tried that but got:- > Open "A:/test/data"+DATE$ For Output As #2 Error : Could not find the file > This seems to work: > s$ = "A:test"+datetime$(now) > Open s$ For Output As #1 > Edit. the "/" seems to be the issue. Change to the required directory first then Open and see if that helps. Edit 2. > mkdir "test" > chdir "test" > s$ = "data_"+DATE$ > Open s$ For Output As #1 > files A:/test <DIR> . <DIR> .. 17:08 04-03-2024 0 data_04-03-2024 2 directories, 1 file, 15032320 bytes free > Edited 2024-03-04 16:10 by phil99 |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
Thanks, I'll work with that and see how I go. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
Thanks, Geoff's example worked for me. I now have it running OK "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
Well it seemed to work. I found after saving the file, I can change Date$ in the line Open "A:/weather/data"+Date$ For Input As#1 to anything and it still reads the file OK. I've tried all sorts of things but no go. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
Using a PicoMite with V 5.07.06 Still working on this. In the code below I have saved the value 'Z' to "A:/test/tuesday". I then save values to "A:/test/monday". But I can then retrieve these values from "A:test/tuesday". It seems the file name does not matter ? ' Option EXPLICIT Option DEFAULT NONE Dim Integer x,y,a Dim Integer Test(12) Dim Integer z Open "A:/test/tuesday" For Output As#4 Print #4, z Close #4 For y = 1 To 10 Test(y)=y Next y Open "A:/test/monday" For Output As#4 For a = 1 To 10 Print #4, Test(a) Next a Close #4 For x = 1 To 10:test(x)=0:Next x Open "A:/test/tuesday" For Input As#4 For x = 1 To 10 Input #4, Test(x) Next x Close #4 For x = 1 To 10 Print x; Next x ESC:Exit F1:Save F2:Run F3:Find F4:Mark F5:Paste Ln: 11 Col: 3 INS Edited 2024-03-05 05:49 by palcal "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9115 |
should be |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
Thanks Peter, another stupid mistake. Back to trying to datestamp the file. Edited 2024-03-05 05:54 by palcal "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
Ok so I tried this... Option EXPLICIT Option DEFAULT NONE Dim Integer x,y,a Dim Integer Test(12) For y = 1 To 10 Test(y)=y Next y Open "A:/test/"+Date$ For Output As#4 For a = 1 To 10 Print #4, Test(a) Next a Close #4 For x = 1 To 10:test(x)=0:Next x Date$ = "05-03-2025" Open "A:/test/"+Date$ For Input As#4 For x = 1 To 10 Input #4, Test(x) Next x Close #4 For x = 1 To 10 Print test(x); Next x Using Date$ as the file name but then I change the date to the following year and the code runs OK although the file name has changed. I was thinking Date$ would be expanded into the actual date but obviously not. I thought Datestamping a file would be simple but obviously not. Edited 2024-03-05 06:54 by palcal "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
Does this make any difference? Fname$ = "A:/test/"+Date$ Open Fname$ For Input As #4 For x = 1 To 10 Input #4, Test(x) Next x Close #4 For x = 1 To 10 Print test(x); Next x |
||||
PEnthymeme Regular Member Joined: 27/12/2023 Location: United KingdomPosts: 42 |
Is the issue here that date$ always returns the current date, regardless of setting it with date$="05-03-2025" in your code. Open "A:/test/"+Date$ For Output As#4 The above works as expected OpenDate$ = "05-03-2025" Open "A:/test/"+OpenDate$ For Input As#4 Modified not to use date$.... Forgive me if I am missing the point here - but the above now works as expected. Px |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
Yes it does if you expand Date$. Put simply I want to save a file each month, so I have to use a different file name each month otherwise next month, this months data will be overwrittren. I want the file name to change automatically each month that is why I was trying to incorporate the Date in the file name. Eventually if I get it working I was just going to use the month. Mid$(Date$,4,2) in the file name then I would be able to print out a full years data month by month. I thought this would be something that is quite common but obviously not. As Geoff said above... But it doesn't work. Edited 2024-03-05 09:24 by palcal "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
This works for me with data in the editor: > mkdir "test" > save "a:/test/data"+mid$(date$,9,2)+mid$(date$,4,2)+".dat" > files "test/" A:/test <DIR> . <DIR> .. 18:37 04-03-2024 32 data2403.dat 2 directories, 2 files, 15458304 bytes free Similar should work with OPEN, PRINT, and CLOSE in a program. ~ Edited 2024-03-05 09:43 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6098 |
My method: ' logtime$ = MID$(DATE$,9,2)+MID$(DATE$,4,2)+LEFT$(DATE$,2)+LEFT$(TIME$,2)+MID$(TIME$,4,2)+RIGHT$(TIME$,2) logfile$ = "log"+logtime$+".txt" PRINT logfile$ Just omit the Time$ portion as desired. Jim VK7JH MMedit MMBasic Help |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
Thanks Lizby and Jim, I'm half way through mowing 1/2 acre, I'll try it out this afternoon. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
OK I seem to have it working. Thanks for the help. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Print this page |