-> DW> -> IF NOT LEN(k$) THEN GOTO Again
-> DW> IF LEN(k$) = 0 THEN GOTO Again
-> DW> or
-> DW> IF k$ = "" THEN GOTO Again
-> A DO loop would be more to the point.
-> DO: k$ = inkey$: LOOP UNTIL k$ > ""
I agree. My point was to criticize the IF NOT LEN(k$)... idea, not the
GOTO structure. The following loop would suffer from the same problem:
k$ = ""
DO WHILE NOT LEN(k$)
k$ = INKEY$
LOOP
This, too, will loop for ever, even after a key has been pressed, since
it contains the same (rather common) logical error. To fix it, the
second line must be re-written as DO WHILE k$ = "" , or something
similar.
-> If you wanted specific input:
-> DO
-> k% = INSTR(" ABCDEFG", UCASE$(INKEY$)) - 1
-> LOOP UNTIL k% > 0
-> SELECT CASE k%
-> CASE 1: PRINT "A"
-> CASE 2: PRINT "B"
-> CASE 3: PRINT "C"
-> CASE 4: PRINT "D"
-> CASE 5: PRINT "E"
-> CASE 6: PRINT "F"
-> CASE 7: PRINT "G"
Hmmm...
My inclination would be to write the INKEY loop as something like:
DO: k$ = UCASE$(INKEY$): LOOP UNTIL k$ >= "A" AND k$ <= "G"
Then simply PRINT k$
Wouldn't that be a whole lot simpler?!
And if I wanted to do other things, depending on which key has been
pressed, I might write them as subroutines and call them with something
like:
ON ASC(k$) - 64 GOSUB First, Second ... and so on.
I know it's terribly un-trendy at present to use this kind of coding,
but it is so much easier than all this CASE stuff!
dow
--- PCBoard (R) v15.3 (OS/2) 5
---------------
* Origin: FidoNet: CAP/CANADA Support BBS : 416 287-0234 (1:250/710)
|