Need some help trying to build a string
Don M
Posts: 1,652
What I'm trying to do is make a file name for SD card based on month/day/hour.
The file name would look like this: mmddhh.txt So for todays date at 1600 hours would be 020816.txt
I can get the month / date / hour from the clock object like this using todays date:
DecN is a method for setting the number of digits.
If I use term.decn(month,2) I get 02. Term.decn(date,2) I get 08. Term.decn(hour,2) I get 16.
So how do I build a string using the above?
I tried declaring a word buffer called FileName[3] and using it like this:
Then tried printing it out like this: term.decn(@FileName,6) but I get a result of 012496 which makes no sense to me.
Can someone help me out with this?
Thanks.
The file name would look like this: mmddhh.txt So for todays date at 1600 hours would be 020816.txt
I can get the month / date / hour from the clock object like this using todays date:
month := clock.GetMonth date := clock.GetDay hour := clock.GetHour
DecN is a method for setting the number of digits.
If I use term.decn(month,2) I get 02. Term.decn(date,2) I get 08. Term.decn(hour,2) I get 16.
So how do I build a string using the above?
I tried declaring a word buffer called FileName[3] and using it like this:
FileName[2] := clock.GetMonth FileName[1] := clock.GetDay FileName[0] := clock.GetHour
Then tried printing it out like this: term.decn(@FileName,6) but I get a result of 012496 which makes no sense to me.
Can someone help me out with this?
Thanks.
Comments
There's an object called StrFmt posted by LocalRoger with has a method that will do this.
The method is "fdec".
StrFmt is included in the archive of my MAX7219 code.
I'll look for an example of using of the fdec method and post it soon.
The following code should load the string with the time stamp.
I found some other code for numbering files on SD card that Jonny Mac showed on here some time ago.
I used that in conjuction with this that I made and it works:
So thanks for your help and maybe someone else can use this.
Thanks again!
Don
bytemove( @strDATE, string("00.00.0000"),11) 'Setup strDATE template
n1 := SN_.decx(n2, 2) 'Put mm dd yyyy in string @strDATE
bytemove( @strDATE.byte[0], n1, 2 ) 'use simple_numbers: integer to string Date
d1 := SN_.decx(d2, 2) 'as n2>n1, d2>d1 and y2+2000>y1
bytemove( @strDATE.byte[3], d1, 2 ) 'Must keep absolute Index to work
y1 := SN_.decx(y2 +2000, 4) 'Note yyyy is4 places in the bytemove string
bytemove( @strDATE.byte[6], y1, 4 )
--- --- --- ---
Print.str( @strDATE ) 'Print finished @strDATE
bytemove works well. But you have to be very careful about making sure moving the values to the right adress.
If something runs wrong there your code will behave very strange.
best regards
Stefan