And the anti- EXIT FOR brigade will be up-in-arms.
Yep. That's how to look for a number. Actually, there's a missing right bracket: IF INSTR(text$, MID$(search$, I, 1)) THEN EXIT FOR
And the anti- EXIT FOR brigade will be up-in-arms.
INPUT "Insert something..."; s$
FOR a = 1 TO LEN(s$)
IF ASC(s$, a) >= 48 AND ASC(s$, a) <= 57 THEN nr = 1: EXIT FOR ELSE nr = 0
NEXT
IF nr THEN PRINT "Number found." ELSE PRINT "Number not found"
If I were MLambert, I would be feeling unsatisfied with above solutions, for instance:
What if one wants to extract the real numbers in say "You can reach me at -22.17 degrees latitude, -44.96 degrees longitude."
But that wasn’t the question presented. All he wanted was to check for numeric values, not extract them. 😉
Question, who are these "anti- EXIT FOR brigade" and why are they up in arms?
I think a EXIT FOR is just fine, even as good as a WHILE/WEND.
Back in the C-64 days (now I imagine some pitchforks coming out) we were told, don't exit a for loop early, you leave things on the stack, do it too much and the stack will explode and you will get a mem error.
Surely this is no longer a problem? Our new and modern QB64 won't do that, right?
Maybe this brigade is up in arms over some other issue? *shrug*
(By the way, there's another way to do this
Set a var to 0
iterate thru as before, but add the INSTR to it every time
Test if its > 0 at the end.
)