if statment question. please let this be a simple fix.
Rob311
Posts: 83
I'm inputing some numbers as a string to my bs2 (via bluetooth).
when i use an if statement, it will only spit out the 1st number. ie 300 is seen as 3.
also, why cant my if handle more then 1 digit? i know its b.c its a string, but can i use then?
here is a portion of the code
Recive:
'==BT recive==
SEROUT lcdpin, baud19200, [noparse][[/noparse]12] 'clear
SEROUT lcdpin, baud19200, [noparse][[/noparse]"Bluetooth Control"]
'serin pin,baud,[noparse][[/noparse]STR var\how many]
SERIN 0,84,[noparse][[/noparse]STR szData\3] <==== inputs 3 characters as a string
'send confirmation to program
SEROUT 1,84,[noparse][[/noparse]CR,"You sent ",STR szdata, CR] <== spits it back out as the full 3 digit number via bluetooth
'==Display Input==
SEROUT lcdpin, baud19200, [noparse][[/noparse]12] 'clear
SEROUT lcdpin, baud19200, [noparse][[/noparse]STR szData\3] <=== spits it out as full 3 digit number to my lcd screen
DEBUG szdata,CR <=== here it spits out only the first digit (3 if i type in 342)
PAUSE readtime
'==Switch Case==
IF (szdata = "1") THEN <===wont let me use more then 1 digit. why?
SEROUT lcdpin, baud19200, [noparse][[/noparse]12] 'clear
SEROUT lcdpin, baud19200, [noparse][[/noparse]"Case 1"]
PAUSE readtime
GOSUB fowardbump
when i use an if statement, it will only spit out the 1st number. ie 300 is seen as 3.
also, why cant my if handle more then 1 digit? i know its b.c its a string, but can i use then?
here is a portion of the code
Recive:
'==BT recive==
SEROUT lcdpin, baud19200, [noparse][[/noparse]12] 'clear
SEROUT lcdpin, baud19200, [noparse][[/noparse]"Bluetooth Control"]
'serin pin,baud,[noparse][[/noparse]STR var\how many]
SERIN 0,84,[noparse][[/noparse]STR szData\3] <==== inputs 3 characters as a string
'send confirmation to program
SEROUT 1,84,[noparse][[/noparse]CR,"You sent ",STR szdata, CR] <== spits it back out as the full 3 digit number via bluetooth
'==Display Input==
SEROUT lcdpin, baud19200, [noparse][[/noparse]12] 'clear
SEROUT lcdpin, baud19200, [noparse][[/noparse]STR szData\3] <=== spits it out as full 3 digit number to my lcd screen
DEBUG szdata,CR <=== here it spits out only the first digit (3 if i type in 342)
PAUSE readtime
'==Switch Case==
IF (szdata = "1") THEN <===wont let me use more then 1 digit. why?
SEROUT lcdpin, baud19200, [noparse][[/noparse]12] 'clear
SEROUT lcdpin, baud19200, [noparse][[/noparse]"Case 1"]
PAUSE readtime
GOSUB fowardbump
Comments
You could also convert the 3 characters to a number like:
DEBUG szdata,CR <=== here it spits out only the first digit (3 if i type in 342)
TO
DEBUG STR szdata,CR
next convert the string to a number place in a word variable szFinal
szFinal=(szData(0)-48)*100
szData(1)=(szData(1)-48)*10
szFinal=szFinal+szData(1)+szData(2)
IF szFinal = 1 THEN
Jeff T.
EDIT I messed up the string to number conversion......should be correct now
Post Edited (Unsoundcode) : 3/5/2007 7:01:22 AM GMT
Unless I missed it somewhere, you've never shown how the variable "szData" is defined. If it's defined as:
szData VAR BYTE
that's the problem.
Regards,
Bruce Bates
Post Edited (Bruce Bates) : 3/5/2007 2:22:07 PM GMT