Array Access w/ SXB 2 and SX-Key 3.3.0
edgellmh
Posts: 85
I am having problems accessing or assigning array values using a byte variable as the accessor.
I am unable to get code to compile whether or not the accessor is a global or local variable.
The following code does not compile:
DO
strLen = strLen + 1
READ idx, char
idx = idx + 1
string(strlen - 1) = char
GOSUB CalcCRC
IF strLen = 15 THEN EXIT
IF char = EOM THEN EXIT
LOOP
strLen is a local byte variable and string is a global array defined as: string VAR byte(16)
The error message is: ... Error 10, Pass 1: INVALID NUMBER OF PARAMETERS and the line string(strLen -1) = char is highlighted. I get the same error if I just use string(strLen) = char. It compiles fine if I use string(15) = char
I have had the same problem compiling code from examples taken off of this site or from product information code.
marshall edgell
I am unable to get code to compile whether or not the accessor is a global or local variable.
The following code does not compile:
DO
strLen = strLen + 1
READ idx, char
idx = idx + 1
string(strlen - 1) = char
GOSUB CalcCRC
IF strLen = 15 THEN EXIT
IF char = EOM THEN EXIT
LOOP
strLen is a local byte variable and string is a global array defined as: string VAR byte(16)
The error message is: ... Error 10, Pass 1: INVALID NUMBER OF PARAMETERS and the line string(strLen -1) = char is highlighted. I get the same error if I just use string(strLen) = char. It compiles fine if I use string(15) = char
I have had the same problem compiling code from examples taken off of this site or from product information code.
marshall edgell
Comments
You cannot use any math within the array subscript. So the string(strlen -1) is not allowed.
With some simple re-arrangement you can avoid the need to do the subtraction.
See if this works:
DO
· READ idx, char
· idx = idx + 1
· string(strlen) = char
· strLen = strLen + 1
· GOSUB CalcCRC
· IF strLen = 15 THEN EXIT
· IF char = EOM THEN EXIT
LOOP
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Does that byte of memory hold "A", 65, $41 or %01000001 ?
Yes it does...
·
I get the exact same error message with the new version. I have tried that format in several contexts and it always fails if the accessor is a variable. It works fine if the accessor is a constant.
marshall
strlen cannot be a local variable.
If you could post the whole program, it would be helpful.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Does that byte of memory hold "A", 65, $41 or %01000001 ?
Yes it does...
·
Making strLen a global solved the problem.
Thanks
This is the last bit of code that does not compile.
All of the variables in this are global.
SUB CalcCRC
cValue = crc_HSB ^ cValue >> 4 ^ (crc_HSB ^ cValue)
crc = cValue ^ (cValue << 5) ^ cValue << 12) ^ (crc << 8)
ENDSUB
The first line of code in the subroutine gives the error msg is: INVALID NUMBER OF PARAMETERS
e.g.,
cValue = crc_HSB ^ cValue
cValue = cValue >> 4
tmpB1 = crcHSB ^ cValue
cValue = cValue ^ tmpB1
etc.
Post Edited (JonnyMac) : 10/21/2009 4:14:22 PM GMT