Convert day no. to day name?
I need to convert a day-of-week number (1-7) to a day-of-week name string (Mon-Sun).
I could write a long conditional statement to do this (IF ELSEIF... perhaps) but
is it possible to use LOOKDOWN (dayNo: "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
to return the day name directly?
If not, what about using LOOKDOWN's returned index number to take multi-character strings out of an array.
Any suggestions appreciated - I'm new to spin.
David
I could write a long conditional statement to do this (IF ELSEIF... perhaps) but
is it possible to use LOOKDOWN (dayNo: "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
to return the day name directly?
If not, what about using LOOKDOWN's returned index number to take multi-character strings out of an array.
Any suggestions appreciated - I'm new to spin.
David
Comments
Spin is a lot like C as far as strings are concerned. They are represented by their addresses and they are stored in byte arrays and zero-terminated.
There are no string variables nor string arrays.
But you can also define the Stringnames in the DAT section and calculate the pointer. (every name has 3 characters 1 Zero, so the offset is daynumber * 4.
This sounds like DS1302 (or similar) code…There are several examples (most in the Completed Projects Forum) of using the DS1302 and the LOOKUP command (in PBASIC) to get the day. While this is different than the LOOKUP command on the Propeller you can use it as Ariba describes or you can populate the index values with the addresses of DATA containing the Day Names, comma delimited for printing. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
David