PDA

View Full Version : Strings and DATA



dunlisting
09-02-2008, 08:22 PM
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
·

Chris Savage
09-02-2008, 09:21 PM
Duplicate post deleted.

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:


String1 DATA "George", 0
String2 DATA "Harry", 0
String3 DATA "Bob", 0
String4 DATA "Michael", 0


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

dunlisting
09-02-2008, 09:28 PM
Many thanks Chris, it was as I thought.

Dunlising

Chris Savage
09-02-2008, 09:42 PM
Here is a quick example of how you might accomplish this task…This is just one way but the most common. Note that the strings are not being printed in the order they are stored.

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

dunlisting
09-02-2008, 10:23 PM
Brilliant!, many thanks Chris