|
Post by jarych on Jun 27, 2019 11:27:05 GMT
(Example uses two FOR loops and MID$() function. )
Example of how to check for several possible invalid characters in input, if program expects to use Whole Numbers as inputs:
invalidchar$="abcdefghijlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,.?/-+" flaginputqual=1 'for good input expected
INPUT "minutes, "; m$ INPUT "seconds, "; s$
rem first check m$ for i=1 to len(m$) for j=1 to len(invalidchar$) if mid$(m$,i,1)=mid$(invalidchar$,j,1) then flaginputqual=0 next j next i
rem last check s$ for i=1 to len(s$) for j=1 to len(invalidchar$) if mid$(s$,i,1)=mid$(invalidchar$,j,1) then flaginputqual=0 next j next i
print "flaginputqual variable value established as ";flaginputqual print "0 indicates bad inputs and 1 indicates good inputs"
END
Some other possibilities for what or how to check, to include other specifications on the inputs or what to look for.
|
|
|
Post by B+ on Jun 27, 2019 13:30:44 GMT
Do you just want to check valid minutes and seconds?
if int(val(m$)) >= 0 and int(val(m$)) < 60 then valid.
Otherwise use INSTR to check for characters in a string.
|
|
|
Post by jarych on Jun 27, 2019 19:23:34 GMT
Do you just want to check valid minutes and seconds? if int(val(m$)) >= 0 and int(val(m$)) < 60 then valid. Otherwise use INSTR to check for characters in a string. I may need to think more carefully about how to use VAL() and INT(). Problem seems that VAL is accepting letter-characters, and this is why I created code to check for the most likely non-digit characters in an input string. I did some thinking about INSTR() but became unsure what to do with it. Currently, my skill in thinking with INSTR() has become too weak. I believe I can do most of what I want using the sample program presented. Inputs are expected to be strings: one of them for holding minutes, and another for holding seconds.
|
|
|
Post by B+ on Jun 27, 2019 21:41:56 GMT
Could check for valid, would be quicker test:
[restart] scan input "(Just enter to quit) Enter a number to test ";n$ if n$ ="" then end OK$ = "1234567890" for i = 1 to len(n$) if instr(OK$, mid$(n$, i, 1)) = 0 then print "Number is not good." : goto [restart] next print "Number is good." goto [restart]
|
|
|
Post by jarych on Jun 28, 2019 2:35:30 GMT
B+ Key to understanding INSTR() is, remember that this looks for a POSITION number. I might be able to understand how to work with INSTR(), that is according to your example, and the JB helpfile. Right now, I am thinking more about using VAL(), INT(), and STR$().
|
|
|
Post by B+ on Jun 28, 2019 13:39:42 GMT
Remember INSTR returns a value of 0 if it does not find a match, that means if one of the characters does not match the OK$ set, it is not valid making the input not valid. So INSTR gives us 2 kinds of information 1. position if present 2. no position means not in OK$ set.
VAL("M") = 0 which is an OK valid minute or second.
I am just saying for digits, checking what's valid is a shorter test that checking all possible invalid characters.
|
|
|
Post by jarych on Jun 28, 2019 16:57:31 GMT
Remember INSTR returns a value of 0 if it does not find a match, that means if one of the characters does not match the OK$ set, it is not valid making the input not valid. So INSTR gives us 2 kinds of information 1. position if present 2. no position means not in OK$ set. VAL("M") = 0 which is an OK valid minute or second. I am just saying for digits, checking what's valid is a shorter test that checking all possible invalid characters. I was coming into that understanding but it took several hours. Nice knowing that VAL() will ignore leading zero.
|
|