Need help with Strings and SERIN, Maybe even a few lines of sample code???
Grant_O
Posts: 36
Hey everyone.
I am trying to·use SERIN·to gather certian string data and match it to Conditional statements.
the strings are "Hello" and "Goodbye".
if the string = "Hello" then the BS2 will go to the lable, Hello:
if·the string = "Goodbye" then the BS2 will go to the lable, Goodbye:
If its something else the BS2 will goto the lable, TryAgain:
I have been trying to figure how to make the BS2 understand these Strings but·I havnt been secessful yet. and the help files dont describe it much. Please help!!!
Thanks.
I am trying to·use SERIN·to gather certian string data and match it to Conditional statements.
the strings are "Hello" and "Goodbye".
if the string = "Hello" then the BS2 will go to the lable, Hello:
if·the string = "Goodbye" then the BS2 will go to the lable, Goodbye:
If its something else the BS2 will goto the lable, TryAgain:
I have been trying to figure how to make the BS2 understand these Strings but·I havnt been secessful yet. and the help files dont describe it much. Please help!!!
Thanks.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
String1 VAR BYTE(10)
MAIN:
GOSUB ClearString
GOSUB GetString
Done = 0
IF String1(0) <> "H" THEN TryNext
IF String1(1) <> "e" THEN TryNext
IF String1(2) <> "l" THEN TryNext
IF String1(3) <> "l" THEN TryNext
IF String1(4) <> "o" THEN TryNext
GOTO Hello
TryNext:
IF String1(0) <> "G" THEN EndTries
IF String1(1) <> "o" THEN EndTries
.
.
EndTries:
GOTO MAIN
' etcetera. Well, I hope you get the idea.
' You COULD store the "Hello" and "Goodbye" check strings
' in a DATA statement, and condense the above code
...
GOTO MAIN
' ************** Subroutines ********************
ClearString:
FOR I = 0 TO 9
String1(I) = 0
NEXT
RETURN
GetString:
SERIN 16, 16384, [noparse][[/noparse]STR String1]
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
That program worked very well with my application.
But hey Mr. Williams,
I'm a little curious about your byte-code scheme. Do you have any information or resources about it? Because variable space is very important as well!
String1 VAR BYTE
MAIN:
GOSUB ClearString
GOSUB GetString
IF String1 <> "H" THEN TryNext
GOTO Hello
TryNext:
IF String1 <> "G" THEN EndTries
GOTO Goodbye
EndTries:
GOTO MAIN
' ************** Subroutines ********************
Hello:
' ... Whatever
GOTO MAIN
Goodbye:
'... More stuff
GOTO MAIN
ClearString:
String1 = 0
RETURN
GetString:
SERIN 16, 16384, [noparse][[/noparse]STR String1] ' Where String1 will be "H" for 'Hello', or "G" for 'Goodbye'
RETURN
' Jon's solution used "bytecodes" of $C0 or $C1 for the input characters,
' but you can just as easily use single type-able characters of "H" or "G".
' I believe you'll have to send the character with a 'linefeed' character after it,
' to tell the BS2 run-time that the "string" is done.
But hey thanks for all the help!
I think I have enough now to get started.