Code: Select all
DECLARE FUNCTION CheckSpace! (Var AS STRING)
DECLARE SUB Parse (Answer$, Word1$, Word2$)
CLS 'clear the screen
CONST True = 1, False = NOT True 'set true and false constants
Phrase1$ = "red vall." 'set the parsed word
Phrase2$ = "blue vall." 'set the second word
Parse Phrase1$, Word1$, Word2$
Parse Phrase2$, Word3$, Word4$
'You can set it for more words, but for now 2 words are good.
IF Word1$ = Word2$ THEN PRINT "Match!"
IF Word1$ = Word3$ THEN PRINT "Match!"
IF Word1$ = Word4$ THEN PRINT "Match!"
IF Word2$ = Word3$ THEN PRINT "Match!"
IF Word2$ = Word4$ THEN PRINT "Match!"
IF Word3$ = Word4$ THEN PRINT "Match!"
FUNCTION CheckSpace (Var AS STRING)
FOR i = 1 TO LEN(Var)
IF MID$(Var, i, i - 1) = " " THEN CheckSpace = True
NEXT
END FUNCTION
SUB Parse (Answer$, Word1$, Word2$)
Parse:
Answer$ = LTRIM$(RTRIM$(Answer$)) 'Gets rid of all the spaces
IF Answer$ = "" OR Answer$ = " " THEN Word$ = Answer$
'If the first word is null or
'a space, we return it.
Index = 0 'Set the index to 0
DO 'start the loop
Index = Index + 1 'start the heart of the loop
IF MID$(Answer$, Index, 1) = " " THEN EXIT DO: GOTO ParserHandler
'Check for the space and if
'it is it goes to the handler
LOOP 'loop da loop!
ParserHandler:
Word1$ = LEFT$(Answer$, Index - 1) 'just puts the first word
'into the FirstWord$ string
Answer$ = RIGHT$(Answer$, Index + 1) 'puts Word$ out of answer
'Now is the time that you want to store/use the first word
'becuase it will be written over nex time.
IF CheckSpace(Answer$) THEN 'if there are spaces
GOTO Parse 'parse again
ELSE 'otherwise
Word2$ = LTRIM$(RTRIM$(Answer$)) 'Set the last word
EXIT SUB 'exit the function
END IF 'exit the if
END SUB