Shop OBEX P1 Docs P2 Docs Learn Events
Storing user input in array var / String handling — Parallax Forums

Storing user input in array var / String handling

..sd..sd Posts: 2
edited 2006-03-14 23:06 in Learn with BlocklyProp
Hi there,


Thank you very much for reading my post. I hope that someone of you out there can help me with this. I discussed it with my teacher, who could not quite help me. My issue is as follows:

I would like to store user input (through DEBUGIN) in an array var. However, I may not create an array that contains over 11 value's. Running "Array VAR Word(x)" with x>11 returns an error. However, I would like to be able to store about 30 values, preferably without having to switch var name while looping through the value's again. Is there a way in which I can make "Array VAR Word(30)" work?
If not, I could also use string handling features to reach my goal. For this, I will need to append the user input to a var, and then read out the var's content digit by digit (each user input is one digit, 1 through 9). The appending shouldn't be a problem, the looping through every single digit is. Is there a function which can help me with this?

If you do not quite understand, the source code included below might help you. It is ofcourse not working, for the first line will return an error. It basically shows what I'm about to do, but very much simplified. I hope someone can help me. Thank you in advance!


Cheers,
Coen


array VAR Word(30)
counter VAR Byte

FOR counter=0 TO 29
  DEBUGIN DEC array(counter)
NEXT
FOR counter=0 TO 29
  IF (array(counter) = 1) THEN PULSOUT 12, 750-125: PULSOUT 13, 750+25
  IF (array(counter) = 2) THEN PULSOUT 12, 750-125: PULSOUT 13, 750+125
  IF (array(counter) = 3) THEN PULSOUT 12, 750-25: PULSOUT 13, 750+125
  IF (array(counter) = 4) THEN PULSOUT 12, 750-125
  IF (array(counter) = 6) THEN PULSOUT 13, 750+125
  IF (array(counter) = 7) THEN PULSOUT 12, 750+25: PULSOUT 13, 750-125
  IF (array(counter) = 8) THEN PULSOUT 12, 750+125: PULSOUT 13, 750-125
  IF (array(counter) = 9) THEN PULSOUT 12, 750+125: PULSOUT 13, 750-25
NEXT

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-14 19:31
    You have to start with the basics, and the first thing you bump up against is that the BASIC Stamp does not have enough RAM to hold 30 bytes, let along 30 words. You've got choices: use Nib(30) for your array if the choices -- as indicated by your code -- are limited to 9, or capture an input and then put it into the EEPROM with WRITE, then use READ to retrieve the values later. The last choice will work for bytes and words, and also makes the choices non-volatile; that way you could use SERIN with a timeout (instead of DEBUGIN) and the program would run with the last entered values.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • ..sd..sd Posts: 2
    edited 2006-03-14 23:06
    Thank you Jon! I could not find the exact details on creating array's in my booklet; I thought Word(30) chopped a Word var into 30 seperate value "spots", but it puts 30 of 'em together. Instead I should've used Nib, indeed. Thank you very much!
Sign In or Register to comment.