ra7en
New Member
Posts: 7
|
Post by ra7en on Sept 24, 2023 0:52:18 GMT
HI all, i understand the new forum but where did my old account go? o well.
anyways. been banging my head for hours today on this one line. Moving a game guide to a pdf, so have to change a few things, and qb64 to the rescue works great. tons of it edited. however stuck on one function:
this is pulled from a very large text file. Here is a sample line
data$ = "Leave the boat < 7"
I want to search for this line so what I do is simply do a left$ search. but it doesnt work, even tried instr.
example:
if left$(data$,5)="Leave" then go to a sub. ' it never goes to a sub as I have a stop print text:end for debugging
if instr$(data$,"Leave")>=1 then go to a sub ' it never goes to a sub as I have a stop print text:end for debugging
I have no idea what this is not working. It should read that line and act on it, but skips right over it.
Here is a live sample
IF INSTR(aline, "<") >= 1 THEN
IF LEFT$(aline, 5) = "Leave" THEN PRINT "found": END
END IF
It DOES FIND THE "<" if I put it on a line by itself. but the rest it just skips. even if I put it on a line by itself as shown above.
Plz tell me it is something REAAAALLY stupid on my part :-)
Thanks guys. Like the new look!!
|
|
|
Post by bplus on Sept 24, 2023 3:24:55 GMT
Left$(string$, numberOfChars) = the first numberOfChars of the string so
Print Left$("Hello World", 2) ' = "He" Print Left$("Hello World", 5) ' = "Hello"
Now Instr(string$, searchString$) IS you searcher function and it returns the position where it first finds search string from left so
Print Instr("Hello World", "l") ' = 3 print Instr(3+1, "Hello World", "l") ' = 4 Print Instr(4+1, "Hello World", "l") ' = 10
When I say = in above I mean that is what will be printed.
|
|
|
Post by bplus on Sept 24, 2023 3:36:43 GMT
Hello Raven I see you are new so welcome!
OK now about this: if left$(data$,5)="Leave" then go to a sub. ' it never goes to a sub as I have a stop print text:end for debugging
Here is my mod of your code:
Data1$ = "Leave the boat < 7" ' <<< Data is a keyword so put a number or something before the $ If Left$(Data1$, 5) = "Leave" Then GoTo asub ' it never goes to a sub as I have a stop print text:end for debugging
ReturnMeHere: Print "This is the end." End
asub: ' You GoTo a Label: But really do want to GoSub with a Return or Goto anywhere the to Label takes us? Print "I left data long ago." GoTo ReturnMeHere
|
|
|
Post by bplus on Sept 24, 2023 3:47:17 GMT
And here is a sample of using a Data statement:
Data Leave,the,boat,and,fish,from,the,shore
For i = 1 To 3 Read word$ Print Left$(word$, 3) Next
|
|
|
Post by bplus on Sept 24, 2023 3:53:45 GMT
Bonus! Here is a GoSub example
Data Leave,the,boat,and,fish,from,the,shore
For i = 1 To 8 Read word$ Print Left$(word$, 4) If Left$(word$, 2) = "fi" Then GoSub IFoundFish Next End IFoundFish: Print "Hey here is a fish!" Return
|
|
ra7en
New Member
Posts: 7
|
Post by ra7en on Sept 24, 2023 4:01:27 GMT
HI thanks for the reply. Not old, ust new account - dunno where mine is at LOL
OK the last 2 examples do not apply as they are not the same.
I am pulling line by line from a text file I have some 20k lines. I am pulling all the "Leave" (somewhere) that is the first word of these lines I pull.
input #1, aline if left$(aline,5)="Leave" then.... <-- it's not doing this. for some reason it is ignoring it
hope that makes better sense.
|
|
|
Post by bplus on Sept 24, 2023 4:05:12 GMT
Post above was edited
|
|
|
Post by bplus on Sept 24, 2023 4:08:12 GMT
LOL Left$("Leave", 5) IS "Leave"
|
|
ra7en
New Member
Posts: 7
|
Post by ra7en on Sept 24, 2023 4:08:16 GMT
Yup dim aline as string
currently just for checking I am using
IF LEFT$(lcase$(aline$), 5) = "leave" THEN PRINT "found": END
but it just whizzes by
|
|
|
Post by bplus on Sept 24, 2023 4:13:33 GMT
Yup dim aline as string currently just for checking I am using IF LEFT$(lcase$(aline$), 5) = "leave" THEN PRINT "found": END but it just whizzes by Need to see more code, that line should stop execution when found leave. Or Leave! If you are really looking for "Leave" then lcase$ is screwing you up.
|
|
ra7en
New Member
Posts: 7
|
Post by ra7en on Sept 24, 2023 4:20:55 GMT
LOL Left$("Leave", 5) IS "Leave" dim aline as string
input #1, aline
aline = "Leave the big long string follows here......."
so aline is THE FIRST WORD, it should find see it.
if left$(aline,5)="Leave" then do something end if
but it skips that section.
so all the following should work but they just miss it
IF mid$(aline,1,5)="Leave" THEN PRINT "found": END
if left$(aline,5)="Leave" then.... instr(aline,"Leave")>=1 then....
so tried something new
i have a key character I use for specifics... not relavant here but it does find it because I want a specific "Leave"
IF INSTR(aline$, "<") >= 1 THEN '<--- this is my key. it finds this
IF MID$(aline, 1, 5) = "Leave" THEN PRINT "found": END '<-- but gets here and skips because this "Leave" is in the same line as the "<"
END IF
if I get rid of the "<" if then section, and jst use the left$ - it works.
What is wrong? thanks
|
|
|
Post by bplus on Sept 24, 2023 4:40:41 GMT
Is it possible that Leave is not the first 5 characters in aline$ that you might have a tab chr$(9) starting the line?
But this
IF instr(aline,"Leave") >=1 then....
should catch that.
Also you can try "Line Input" instead of "Input" in case your file has commas. Input stops for commas, Line Input keeps on reading the line.
|
|
ra7en
New Member
Posts: 7
|
Post by ra7en on Sept 24, 2023 4:50:04 GMT
I'll tinker with it some more. I thought of the hidden characters. I'll have to turn that on in my n++ currently seems to be working if it just at the beginning. I'll keep an eye on it. report back if I find something :-)
Getting late here. so bbl!! cheers!!
|
|
|
Post by bplus on Sept 24, 2023 5:01:45 GMT
OK
Print asc(aline, 1) 'tells us if tab is there = 9 or something else not seen?
|
|
|
Post by bplus on Sept 24, 2023 12:36:33 GMT
Maybe for debugging you could print each line as you get it from file. Use sleep to pause the lines until you see each one individually.
It's also possible your file only uses Chr$(10) to separate lines instead of old standard Chr$(10) + Chr$(13) 2 byte combo.
Still with all this LeavePosition = Instr(aline, "Leave") ' <> 0 means we have caught Leave word should catch the Leave word anywhere in the string = aline.
By any chance are you on Linux or Mac, not Windows?
|
|