BS2 - Tips for Quicker Array Writing
olefalcon
Posts: 2
From the official BASIC Stamp Help document, it seems the most basic way of writing to an array is like this:
I know there is also a loop you can use to print the same thing to many slots of the array like this:
I am wondering how I would go about forming a function that takes a list or string of values and writes them into an array. In javascript it is easy to write into an array like this:
If you have upwards of twenty or thirty values you want to write into an array, you really don't want to type "myArray(0) =" every time you have a value to add.
If string handling is a solution, the values I am using are bit-sized (1 unit long), so a string like "AGAB" could become "A", "G", "A", "B", but I don't know how to do that.
Thanks for any help!
Oh and I am using BS2 with PBASIC 2.5
I reedited the post showing that the array can actually be bit datatypes, so storage is NOT the concern here!
myArray VAR Bit(30) myArray(0) = "A" myArray(1) = "B" myArray(2) = "G"
I know there is also a loop you can use to print the same thing to many slots of the array like this:
myArray VAR Bit(30) i VAR Bit FOR i = 0 TO 9 myArray(i) = "B" NEXT
I am wondering how I would go about forming a function that takes a list or string of values and writes them into an array. In javascript it is easy to write into an array like this:
var array[] = ["A", "B", "G"]
If you have upwards of twenty or thirty values you want to write into an array, you really don't want to type "myArray(0) =" every time you have a value to add.
If string handling is a solution, the values I am using are bit-sized (1 unit long), so a string like "AGAB" could become "A", "G", "A", "B", but I don't know how to do that.
Thanks for any help!
Oh and I am using BS2 with PBASIC 2.5
I reedited the post showing that the array can actually be bit datatypes, so storage is NOT the concern here!
Comments
Some of the Stamp models have "scratchpad RAM" which can hold more, again as byte values, but not as conveniently as variables.
Since that is not known, I thought I'd post a working BS2 program that uses string constants. Note that these are actually stored in EEPROM using the DATA directive. You'll also find that some string constants are embedded into SEROUT commands.
That is pretty impressive layout for code. I would imagine that is a standard Stamp template for you.