DATA Strings and easier way to access them?
Hello all.... tia for any help...
I was wondering if there is an easy way to solve this problem?· I've done some searching on the forum with little luck.
I know we can use READ to z-strings stored in DATA statments, but is there a better way to access multiple strings?·
For example, suppose I have the following strings stored
stringdata:
· DATA· "String1",0
· DATA· "Stringsasdfa",0
· DATA· "newString asdfas",0
Is there any easy way to access "Stringasdfa" using an index?
Right now I just do this...
stringdata0:
· DATA· "String1",0
stringdata1
· DATA· "Stringsasdfa",0
stringdata2
· DATA· "newString asdfas",0
But I have lots of data to store!· It's for a basic menu system for me.· A similar sample with code is attached...
Thanks,
Mike
I was wondering if there is an easy way to solve this problem?· I've done some searching on the forum with little luck.
I know we can use READ to z-strings stored in DATA statments, but is there a better way to access multiple strings?·
For example, suppose I have the following strings stored
stringdata:
· DATA· "String1",0
· DATA· "Stringsasdfa",0
· DATA· "newString asdfas",0
Is there any easy way to access "Stringasdfa" using an index?
Right now I just do this...
stringdata0:
· DATA· "String1",0
stringdata1
· DATA· "Stringsasdfa",0
stringdata2
· DATA· "newString asdfas",0
But I have lots of data to store!· It's for a basic menu system for me.· A similar sample with code is attached...
Thanks,
Mike
Comments
There are a number of ways to access multiple strings.
1) Simply read through all the strings (counting the zeros) until you find the one you want
2) Make them fixed length and offset the read position by stringnumber * length
3) Prefix each string with a byte count. Read the byte count then offset the read position by that value
4) Make a seperate data section with a list of string lengths, then add that value to the offset
If the string data is > 255 bytes you'll have to use word variables. Like this:
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"Remember, you are unique, just like everyone else." Unknown.
·
DATA "First",0
DATA "Second",0
I write Second to the display (I have a 2x16 LCD) and "Second" shows on the display. If I now write First to the display, it appears as "Firstd" because 'Second' has six characters and 'First' has five characters. When I fix the width to the width of the display:
DATA "First
",0 'both have sixteen characters where the dashes would be spaces in my
DATA "Second
",0 'code but I wanted it to display correctly in the post
Now, Second will display "Second" and First will display "First" because the line is always overwritten.
I'd like to hear more about your menu implementation. I have mine operational. I have a main menu and each item on the main menu has a single sub menu. My intent is to have each sub menu item perform an action but I haven't got that far.
Joe
Thanks for the info... I've also just started. My implementation allows for up to 16 menu items and 16 sub menus per menu item... (upper nibble of byte = menu, lower nibble of byte = submenu)...
I'm working on ways to trim the if statements down to something more managable... my next post! I'll start a new thread for the optimization... watch for it in the next few days....
I'm sure we can swap code and look for advantages....
Thanks,
Mike
The menu has been changed to protect the innocent! [noparse]:)[/noparse]· However, this is not behaving as expected... the only difference between this code and the original LCD_STR code is the lack of supporting the Z flag...· but when I add
········menumain = menumain + Z it fails because menumain is a string pointer I believe.... so is that what is failing here?· If so... I would like to just extend LCD_STR to include a third parameter (index) that would handle this... but I had problems doing that as well...
For reference here is the LCD_OUT and LCD_STR as they exist today...
Thanks,
Mike
You are incrementing temp4 twice in the second loop. Instead of printing "mike8cha" you are printing "mk8h". Move the first "inc temp4" statement before the "do" statement.
Dave
So here is my final solution!
Let me start·by explaining the DATA statements...· The byte prior to the string is the the count in bytes of the entire line (including the count and 0)
EG... if you wanted one called "hello world" it would be:
······· DATA· 13,"hello world",0
I then use these bytecounts to determine how far forward to move the start of the string... I also use this bytecount to determine the number of spaces needed to fill the line on my LCD (4x20) to handle overwritting a longer string with a shorter one!
Feel free to comment/fix! [noparse]:)[/noparse]
Thanks,
Mike
Looks cool.
If you test __PARAMCNT you could make it work for literal strings too.
If __PARAMCNT is 2 then it's a literal string, if __PARAMCNT is 3 then it's a label and an index.
Then you could do:
LCD_STRW2 MainMenu, 1
LCD_STRW2 "Testing"
LCD_STRW2 MainMenu, 2
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"Remember, you are unique, just like everyone else." Unknown.
·
I was following this thread and wondered how I might store my menu items without spaces. I have a DO loop that also calls LCD_OUT but it is in a separate function. I was going to try modifying it to return the number characters it writes and use that to write spaces to the display like you do at the end of LCD_STRW2. I'll let you know.
Did you have some thoughts on how you would indicate the active menu item on the screen? I display a right-pointing arrow as a cursor in the first column. To move to another item, I use a four-position switch to navigate (eg, down moves the cursor to the next item and up moves it to the previous item). There is some administration to provide for moving the menu around on the screen but that might be a different post.
Joe
IE..
My display shows:
Main Menu
Blah1
Pressing one of my direction keys (left or right) produces the next menu item...
Main Menu
Blah 2
etc...
I then have a select key which selects the current shown menu item to do work on that item...
Thanks,
Mike