Searching a file for a string
Posted: Tue Sep 23, 2003 1:00 am
I'm trying to write a function to search a file for a string, and once found, return with "yes" (for found).
Here's what I think is a finished function, but was wondering if you could check it through because I'm a QB newb.
FUNCTION SearchFile (FileName$, Name$)
NameLen = LEN(Name$)
SearchNum = 1
Found$ = "no"
OPEN FileName$ FOR INPUT AS #1
DO UNTIL EOF(1)
LINE INPUT #1, LineText$
LineLen = LEN(LineText$)
IF MID$(LineText$, SearchNum, NameLen) = Name$
Found$ = "yes"
ELSE
IF SearchNum = LineLen THEN
GOTO NextLine
END IF
SearchNum = SearchNum + 1
END IF
NextLine:
LOOP
CLOSE #1
Name$ = Found$
END FUNCTION
-Stu
Here's what I think is a finished function, but was wondering if you could check it through because I'm a QB newb.
FUNCTION SearchFile (FileName$, Name$)
NameLen = LEN(Name$)
SearchNum = 1
Found$ = "no"
OPEN FileName$ FOR INPUT AS #1
DO UNTIL EOF(1)
LINE INPUT #1, LineText$
LineLen = LEN(LineText$)
IF MID$(LineText$, SearchNum, NameLen) = Name$
Found$ = "yes"
ELSE
IF SearchNum = LineLen THEN
GOTO NextLine
END IF
SearchNum = SearchNum + 1
END IF
NextLine:
LOOP
CLOSE #1
Name$ = Found$
END FUNCTION
-Stu