Shop OBEX P1 Docs P2 Docs Learn Events
Comparing variable strings with values from PINK... is it possible? Argh! If so — Parallax Forums

Comparing variable strings with values from PINK... is it possible? Argh! If so

latigerlillylatigerlilly Posts: 114
edited 2007-02-08 17:25 in BASIC Stamp
Hi guys,

This is an excerpt from my program that works:

*********beginning of exerpt

counter VAR Word
NBVAR VAR Byte(3)

SEROUT 13,1021,[noparse][[/noparse]"!NB0R01"]
SERIN 12,1021,[noparse][[/noparse]STR NBVAR\3]

GOSUB l4

DO
MAINIO
IF (NBVAR(1) = "g") THEN

**********end of exerpt

Basically, in this above exerpt, I'm comparing the first letter of the variable from PINK with the letter "g" (as in god) and if it matches, then it will display "god" on the LED array on my PDB. However, I'd like to compare not just the first letter, but the whole 3 byte array from PINK to the whole word "god" to see they match before displaying "god" on the LED array. So, I did the following exerpts that didn't work:

**********beginning of exerpt

counter VAR Word
NBVAR VAR Byte(3)
NBVAR2 VAR Word

SEROUT 13,1021,[noparse][[/noparse]"!NB0R01"]
SERIN 12,1021,[noparse][[/noparse]STR NBVAR\3]
NBVAR2 = NBVAR(1) + NBVAR(2) + NBVAR(3)

GOSUB l4

DO
MAINIO
IF (NBVAR2 = "god") THEN

**********The error message was "expected a binary operator or ')'
**********It highlighted the "o" in "god" on the last line of the exerpt when this message was displayed
**********end of exerpt

**********beginning of exerpt

counter VAR Word
NBVAR VAR Byte(3)

SEROUT 13,1021,[noparse][[/noparse]"!NB0R01"]
SERIN 12,1021,[noparse][[/noparse]STR NBVAR\3]

GOSUB l4

DO
MAINIO
IF (NBVAR = "god") THEN

**********The error message was "expected a binary operator or ')'
**********It highlighted the "o" in "god" on the last line of the exerpt when this message was displayed
**********end of exerpt

Please help. What I mean by "it works" is that the program can run while attached serially to my PC. However, I still haven't had a chance to test with PINK yet as the router is in my sister's room and she is asleep.... I want to be able to have people type inputs on an online form to communicate with me. However, I want to be alerted instantly whenever someone uses the word "god" or "odd". Thanks.

Thanks,
Lilly. smile.gif

P.S. Here's the full computer program if you're interested:

' Learning on the PDB - experimental.bs2p

' Spells "dog" on the 7 segment LED display on the PDB as the default.
' Spells "god" on the 7 segment LED display on the PDB when PINK sends the variable into pin 12.
' Spells "odd" on the 7 segment LED display on the PDB when PINK sends the variable into pin 12.
' 7 segment LED display has digits 4, 3, and 2 used on X19.
' 7 segment LED display has segments A through G used on X18. Segment DP is not used.
' Digits 4, 3, and 2 are connected to P5, P4, and P3, respectively.
' Segments A, B, C, D, E, and F are connected to P6, P7, P8, P9, P10, and P11, respectively.
' Segment G is connected to P14.

' {$STAMP BS2p}
' {$PBASIC 2.5}

DEBUG "Program Running!"

counter VAR Word
NBVAR VAR Byte(3)

SEROUT 13,1021,[noparse][[/noparse]"!NB0R01"]
SERIN 12,1021,[noparse][[/noparse]STR NBVAR\3]

GOSUB l4

DO
MAINIO
IF (NBVAR(1) = "g") THEN

' If button 1 is pressed then display god

FOR counter = 1 TO 330
GOSUB hg
PAUSE 5
GOSUB h4
GOSUB l3
GOSUB lg

GOSUB ho
PAUSE 5
GOSUB h3
GOSUB l2
GOSUB lo

GOSUB hd
PAUSE 5
GOSUB h2
GOSUB l4
GOSUB ld
NEXT

ELSEIF (NBVAR(1) = "o") THEN

' If button 2 is pressed then display odd

FOR counter = 1 TO 330
GOSUB ho
PAUSE 5
GOSUB h4
GOSUB l3
GOSUB lo

GOSUB hd
PAUSE 5
GOSUB h3
GOSUB l2
GOSUB ld

GOSUB hd
PAUSE 5
GOSUB h2
GOSUB l4
GOSUB ld
NEXT

ELSE

'If no button is pressed then display dog.

GOSUB hd
PAUSE 5
GOSUB h4
GOSUB l3
GOSUB ld

GOSUB ho
PAUSE 5
GOSUB h3
GOSUB l2
GOSUB lo

GOSUB hg
PAUSE 5
GOSUB h2
GOSUB l4
GOSUB lg

ENDIF
LOOP

l4:
MAINIO
LOW 5
RETURN

l3:
MAINIO
LOW 4
RETURN

l2:
MAINIO
LOW 3
RETURN

h4:
MAINIO
HIGH 5
RETURN

h3:
MAINIO
HIGH 4
RETURN

h2:
MAINIO
HIGH 3
RETURN

hd:
MAINIO
HIGH 7
AUXIO
HIGH 14
HIGH 10
HIGH 8
HIGH 9
RETURN

ld:
MAINIO
LOW 7
AUXIO
LOW 14
LOW 10
LOW 8
LOW 9
RETURN

ho:
AUXIO
HIGH 14
HIGH 10
HIGH 8
HIGH 9
RETURN

lo:
AUXIO
LOW 14
LOW 10
LOW 8
LOW 9
RETURN

hg:
MAINIO
HIGH 6
HIGH 7
AUXIO
HIGH 14
HIGH 11
HIGH 8
HIGH 9
RETURN

lg:
MAINIO
LOW 6
LOW 7
AUXIO
LOW 14
LOW 11
LOW 8
LOW 9
RETURN

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-08 17:24
    Yup, no string compare operators in PBasic. So you have to look at each character. PBasic DOES have 'character' compare operators.

    Didn't we have a post exactly like this about a week back?

    And the first location of an array is offset '0', not '1'. So to look at the first character would be:

    IF (NBVar(0) = "g") AND (NBVar(1) = "o") and (NBVar(2) = "d") THEN
    ...
    END IF
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-02-08 17:25
    Hello,

    There are no string handling functions on the BASIC Stamp. You can store a string as an array of bytes, but the comparison must be done on a byte by byte basis. The quickest example I can think of that demonstrates this is the example code for the RFID Reader. Please see the link below for the example code. This should help you. Take care.

    http://www.parallax.com/detail.asp?product_id=28140

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.