Shop OBEX P1 Docs P2 Docs Learn Events
Array members as alias? (BS2 OEM) — Parallax Forums

Array members as alias? (BS2 OEM)

vaclav_salvaclav_sal Posts: 451
edited 2009-04-07 19:11 in BASIC Stamp
Can a member of an array be assigned an alias name?·
Apparently not.

I have·this code:

I2C_Data VAR Byte(4)

and like to have these alliases

TSL2561_Address VAR· I2C_Data····· ' slave address
TSL2561_Command VAR· I2C_Data····· ' command
TSL2561_Data··· VAR· I2C_Data····· ' data = $03


Editor comes up with an error on
TSL2561_Address VAR· I2C_Data(0)

and
TSL2561_Address VAR· I2C_Data[noparse][[/noparse]0]
··
Is there an alternative to accomplish this?


I am currently passing the variables to a subroutine using LOOKUP to get the array index and like to try eliminating the LOOKUP.
Just for fun so far.


Thanks ·for reading.
Cheers

Comments

  • ZootZoot Posts: 2,227
    edited 2009-04-07 15:25
    You alias "the other way", i.e. if you declare a variable, it can be used *as if it were an array*, so if you name all the elements, you can access as individual ("normal") variables AND as array elements depending on need and context, i.e.:

    
    i VAR Nib ' counter
    
    someVar VAR Byte ' named var AND element "0" of "implied" array someVar
    someVar1 VAR Byte ' ditto, but this element 1
    someVar2 VAR Byte
    someVar3 VAR Byte
    
    ' so now you have 4 variables that ARE ALSO a 4 element array: someVar(x)
    
    someVar = 1
    someVar1 = 10
    someVar2 = 100
    someVar3 = 255
    
    DEBUG CLS
    FOR i = 0 TO 3
      DEBUG "someVar(", DEC1 i,") = ", DEC3 someVar(i), CR
    NEXT
    
    END
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-04-07 19:11
    Thanks - "problem" SOLVED
Sign In or Register to comment.