Shop OBEX P1 Docs P2 Docs Learn Events
Array Access w/ SXB 2 and SX-Key 3.3.0 — Parallax Forums

Array Access w/ SXB 2 and SX-Key 3.3.0

edgellmhedgellmh Posts: 85
edited 2009-10-21 16:07 in General Discussion
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

Comments

  • BeanBean Posts: 8,129
    edited 2009-10-20 17:26
    Marshall,
    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...


    ·
  • edgellmhedgellmh Posts: 85
    edited 2009-10-20 17:36
    Bean

    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
  • BeanBean Posts: 8,129
    edited 2009-10-20 17:44
    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...


    ·
  • edgellmhedgellmh Posts: 85
    edited 2009-10-20 18:06
    Bean

    Making strLen a global solved the problem.

    Thanks
  • edgellmhedgellmh Posts: 85
    edited 2009-10-20 18:17
    Bean

    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
  • JonnyMacJonnyMac Posts: 9,212
    edited 2009-10-21 16:07
    You can only have one operator per line, and parenthesis are not allowed -- break those long lines into individual elements with one operator (you may need a temporary variable or two)

    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
Sign In or Register to comment.