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 : Creating Filename Variables
Author | Message | ||||
Zonker Guru Joined: 18/08/2012 Location: United StatesPosts: 761 |
Good evening all... Was wondering about how to properly open a file on the SD card using a name being held in a text variable. I want to create a filename based on the current system date with ".log" added to the end. logentry: logname$=Date$+".log" Open logname$ For APPEND As #4 If MM.Errno=0 Then Print #4 Logdat$ Close #4 EndIf Return I'm sure there must be a way to do this, but can't seem to find an example.. The manual says it has to be supplied as "file.log" and is hard typed in with the open command. I'm sure this is just a "nubbie" thing trying to type commands.. Thanks for any help...! |
||||
vk4tec Senior Member Joined: 24/03/2012 Location: AustraliaPosts: 239 |
Here is my code file$ = arg$(9) + ".LOG" 'file$ = "SETNAME.LOG" Print file$ Open file$ For append As #3 Print #3, MSG$ Pause 100 Close #3 Might be spaces ? - Andrew - Andrew Rich VK4TEC www.tech-software.net |
||||
vk4tec Senior Member Joined: 24/03/2012 Location: AustraliaPosts: 239 |
If you get stuck, always do a print of your filename That will quickly tell you if you have it wrong logentry: logname$=Date$+".log" print logname$ Open logname$ For APPEND As #4 If MM.Errno=0 Then Print #4 Logdat$ Close #4 EndIf Return Andrew Rich VK4TEC www.tech-software.net |
||||
vk4tec Senior Member Joined: 24/03/2012 Location: AustraliaPosts: 239 |
logname$=Date$+".log" Change to logname$ = Date$ + ".log" - Andrew - Andrew Rich VK4TEC www.tech-software.net |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6100 |
Date$ returns a string that is 10 characters long. The file name can be a maximum of 8 You also missed a comma from print #4, Logdat$ Logdat$="test string"
logentry: logname$=mid$(Date$,1,2)+mid$(date$,4,2)+mid$(date$,7,4)+".l og" print logname$ Open logname$ For APPEND As #4 If MM.Errno=0 Then Print #4, Logdat$ Close #4 EndIf 'Return Jim VK7JH MMedit MMBasic Help |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Depending on the size of the logfile i use the following formats: "YYMMDD" file for each day. (This will be a year 2K1 problem :) ) "MMDDHH" file for each hour. "DDHHM" file for each 10 minutes. "DDHHMM" file for each minute. "HHMMS" file for each 10 seconds "HHMMSS" file for each second. When programs run long you need to be able to 'store' the missing parts. Like "DDHHM" has only a day, hour and minute part. It is missing the year and month part. The easiest way is to create a directory structure for the missing parts. Like "2013\06" in this example. It also prevents of having hundreds of files in one directory, Especially with microcontrolers you need to take care that many files in a directory will slow down performance. Every time a new file is created, which you can detect if the previous filename is not equal to the current filename, is to write the name of the program that creates the logfile, a version number and a full date. This will allow changes in the logfile structure later. The log parser can then use the version numbers to apply the correct parser. Another way for versioning (with 8.3 length file names) is to use the extension to hold a version number a file would then be named "235910.L10" and the next version would be "235910.L20" for a major update and "235910.L11" for a minor update. Microblocks. Build with logic. |
||||
Zonker Guru Joined: 18/08/2012 Location: United StatesPosts: 761 |
Wow... Nice feedback Gents..!! I knew it was just some kind of command typo I wasn't getting right... I kept getting err 5 - Invalid filename... Jim, I like the way you use the mid$ function to strip unwanted dashes from the filename..! I guess right now, I just wanted to test how easy it would be to log data "auto-magic" and have it show up on the SD card. looks like it's going to be easy to do and doesn't take a lot of code... nice..! I'll try some of this out when I get back from work later..!! Edit: Just got back to it... Logging away just fine Thanks TBS..!! |
||||
Print this page |