Shop OBEX P1 Docs P2 Docs Learn Events
arrays..how to question. — Parallax Forums

arrays..how to question.

Joe MJoe M Posts: 45
edited 2006-02-22 20:37 in BASIC Stamp
I need a little basic help(hah!)...

So If I want to define an array and then loop through it, is that possible in pbasic?
i.e.
foo=[noparse][[/noparse]"cat","dog","bird","fish"]
for loop = 1 to 4
debug "foo[noparse][[/noparse]loop]",cr
next

Which leads into my next question, can you reverse and array, or loop through it backwards?


thanks!

-Joe

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-22 20:25
    Joe,

    ·· You are attempting to create an array with string variables which is not a supported variable type on the BASIC Stamps.· You can create an array of bytes and index it within a loop, but not the way you are showing.· What are you trying to accomplish, perhaps there is an easier way.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Joe MJoe M Posts: 45
    edited 2006-02-22 20:33
    Thanks, this is what I want to do, I have 16 leds hooked up to my stamp, and I wanted to use OUTS and turn them on and off.

    So... I'd like to set something/a variable to hold values like "111111000000", "11111100000", "111111110000"... and then loop through it with OUTS = %variable[noparse][[/noparse]x]

    Does that sound possible or am I totally off base?

    Thanks,
    -Joe
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-22 20:37
    PBASIC has a command called LOOKUP that will do what you want it to do. You can also READ elements from a DATA table.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.