Shop OBEX P1 Docs P2 Docs Learn Events
DEBUGIN to get a letter to use as name of DATA block — Parallax Forums

DEBUGIN to get a letter to use as name of DATA block

John KauffmanJohn Kauffman Posts: 653
edited 2013-02-10 18:14 in BASIC Stamp
I want to get from the user a letter and use that letter to identify the appropriate data block.

I have a data block associated with each letter of the alphabet as follows:
A DATA 0,0,0,0,0
B DATA 0,0,0,0,1
C DATA 0,0,0,1,0
...

I have written:
DEBUGIN myLetter
for counter = 0 to 4
READ myLetter+counter, myBit
debug myBit
next

For DEBUGIN value of "B" I should see 00001 but instead get a string for which I can't see a pattern. I think I am misunderstanding the value returned from DEBUGIN when the user types a non-numeric value.

Any thoughts? Thanks.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2013-02-10 15:42
    It would help us if you were to attach your code so we could help you.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-02-10 15:48
    The Stamp Editor (compiler) doesn't do what you think it's doing ...

    The labels A, B, C, etc. have values that is the address of the memory location at the time the statement is compiled. Assuming that the statement labelled A is the first in the program, the label A has the value 0. The label B has the value 5, and the label C has the value 10 ... all because there are 5 bytes produced by each DATA statement.

    The DEBUGIN statement takes the entered letter and stores it in myLetter as the number equivalent in ASCII to the letter. For the capital letters, "A" becomes 65, "B" becomes 66, and "C" becomes 67.

    If you still want to use the capital letters and each entry has 5 bytes, you could use:

    READ (myLetter-"A")*5+counter,myBit
    DEBUG DEC myBit

    Note that, if you enter an invalid character, the READ will use an invalid memory location. Remember that myBit is a number, not an ASCII digit. You need the DEC (or HEX or BIN) formatter to display it properly.
  • John KauffmanJohn Kauffman Posts: 653
    edited 2013-02-10 18:14
    Franklin: I tried to pare down the code so you wouldn't have to read as much, but you are right, I should just post it (20 lines).
    Mike: You are right, my model was not accurate.

    Now that I understand what is happening, a far easier solution has become clear. Much thansk, guys,
Sign In or Register to comment.