Strings and DATA
dunlisting
Posts: 3
Please excuse my 'New Kid on the Block' question,
I need to load a string from a·DATA statement into a variable array. Do I guess that I need to load each byte from the string into each location of the array, there is no way I can just assign the string knowing the start location and load it directly into the variable name?
locations DATA "Barnes","OysterLnBusStp","LaurelGrange","Coop","PloughGnSW","PloughGnS","Library","Chemist","Head First","Boundys"
········· DATA "Willows","BreweryMobray","HardwareShop","CarlSarah","Cleaners","POffice","BeautyLnge","Changes","ClockHse","210High"
name VAR Byte(13)
· 'name(0) = "s"
· 'name(1) = "t"
· 'name(2) = "r"
· DEBUG STR name, CR
Hoping one of you Gurus can guide me.
Thanks
Dunlisting
·
I need to load a string from a·DATA statement into a variable array. Do I guess that I need to load each byte from the string into each location of the array, there is no way I can just assign the string knowing the start location and load it directly into the variable name?
locations DATA "Barnes","OysterLnBusStp","LaurelGrange","Coop","PloughGnSW","PloughGnS","Library","Chemist","Head First","Boundys"
········· DATA "Willows","BreweryMobray","HardwareShop","CarlSarah","Cleaners","POffice","BeautyLnge","Changes","ClockHse","210High"
name VAR Byte(13)
· 'name(0) = "s"
· 'name(1) = "t"
· 'name(2) = "r"
· DEBUG STR name, CR
Hoping one of you Gurus can guide me.
Thanks
Dunlisting
·
Comments
Since there is no string support on the BASIC Stamps an array can be used to hold a single string up to the number of characters the array is defined for. Each character would have to be loaded one at a time. It would not be easy to implement using your current DATA arrangement as there is no way to tell where one string ends and the next begins. It would be easier if each word was zero-delimited as follows:
In this manner you can use a loop to populate the array until you hit a zero byte. To start you need only know the start address of the data.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Dunlising
In this example each data block has an address. When we want to load the string we simply load the work variable with the address of the string and call the Get_String subroutine which then populates the string, zero-delimited. This in turn makes it easy to print using the STR modifier of the DEBUG command as shown. I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering