Shop OBEX P1 Docs P2 Docs Learn Events
2-D variable array — Parallax Forums

2-D variable array

MacGeek117MacGeek117 Posts: 747
edited 2005-03-10 03:50 in BASIC Stamp
How do you make one with a BS2?
bugg

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
But I canna change the laws of physics, Captain!

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-03-09 18:44
    PBASIC does not support two-dimensional arrays.·

    You can use a 1-dimensional array and some crafty coding.· Let's say you want a 2x3 array of bytes.

    myArray········ VAR···· Byte(6········· ' 2 x 3 bytes
    row············ VAR···· Nib
    col············ VAR···· Nib
    idx············ VAR···· Nib
    Main:
    · row = 0
    · col = 2
    · idx = row * 3 + col
    · myArray(idx) = 10
    ·


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA


    Post Edited (Jon Williams) : 3/9/2005 6:50:16 PM GMT
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-03-10 01:16
    Bugg,

    Here is a slightly more expanded version of that which I posted a couple months ago. The problem is that you can quickly run out of space as 26 bytes of variable will dissapear pretty quickly. This sample defines a 2x4 table of a two byte variable.

    Jim

    Edit: Actually, in looking at the code again, there is a glaring bug in how I set and retrieve the contents of the variable. I'm setting and retrieving a single byte, when the variable is supposed to be two bytes. But that doesn't change the basic concept of how the pointer works to get to the location in the array.

    Post Edited (Jim McCorison) : 3/10/2005 1:19:52 AM GMT
  • MacGeek117MacGeek117 Posts: 747
    edited 2005-03-10 03:10
    If there is a next version of PBASIC could you please have 2D arrrays?
    Thanks Jon nd Jim!
    bugg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    But I canna change the laws of physics, Captain!
  • Pinoy NYCPinoy NYC Posts: 30
    edited 2005-03-10 03:50
    it would be good if we can also have:

    1.) string type variable
    2.) signed byte, word/integer, doubleword/long integer
    3.) double/floating type variable
Sign In or Register to comment.