|
Post by jarych on Jun 30, 2019 8:59:37 GMT
Sample program to check that two variables are whole numbers, and allowing no more than one of them to be 0.
Based on the help for INSTR() which B+ gave.
flagvalidinput=1 'assuming will be good needfrom$="1234567890"
input "give some minutes. ";M$ input "give some seconds. ";S$ if M$="" then M$="0" if S$="" then S$="0"
for mloop=1 to len(M$) if instr(needfrom$,mid$(M$,mloop,1))=0 then flagvalidinput=0 next mloop for sloop=1 to len(S$) if instr(needfrom$,mid$(S$,sloop,1))=0 then flagvalidinput=0 next sloop REM in case both inputs are zero , invalid input if M$="0" and S$="0" then flagvalidinput=0
PRINT "if flagvalidinput is 0 then bad but if 1 then good; and yours is ";flagvalidinput
end
|
|
|
Post by B+ on Jun 30, 2019 13:44:33 GMT
Hi jarych,
I wonder if you know you can input numbers too.
[getsecs] Input "Please enter seconds, 0 to <60 ";secs If secs >= 0 and secs < 60 and int(secs) = secs then 'secs good... ss$ = right$("00" + str$(secs), 2) ' < to compare to secs in right$(time$, 2) else goto [getsecs] end if ...
|
|
|
Post by jarych on Jun 30, 2019 18:42:09 GMT
Hi jarych, I wonder if you know you can input numbers too. [getsecs] Input "Please enter seconds, 0 to <60 ";secs If secs >= 0 and secs < 60 and int(secs) = secs then 'secs good... ss$ = right$("00" + str$(secs), 2) ' < to compare to secs in right$(time$, 2) else goto [getsecs] end if ...
So many ways to play with the logic. I just feel more comfortable accepting the input as strings, and then examine the string input. I do not always know how to make more efficient code, so some of what I do tends to be longer. Part of the thinking is, I never really know what the user will try to put in. When you showed how to use INSTR(), and I finally understood it better, I liked it.
|
|
|
Post by B+ on Jul 1, 2019 15:20:33 GMT
Yeah, you may be right, if you will ultimately compare string of input to string of time... it makes $.01's
|
|