[comp.sys.ibm.pc] QBasic null input query

marquis@qal.qal.berkeley.edu (Roger Marquis) (03/27/89)

     How do you distinguish between a null input string (i.e., 
the return key) and a zero in QuickBasic? I've tried INKEY$, 
INPUT and INPUT$. Simply hitting return sets the value at zero
regardless of initialization or anything else I've tried. I need
to loop until an integer between zero and nine is entered. Here's 
where I'm stuck:

 NCROSS$ ="" 
 WHILE NCROSS$ = ""
      CLS : LOCATE 3, 1
      PRINT "               Input cross pattern:"
      PRINT : PRINT : PRINT
      NCROSS$ = INPUT$(1): NCROSS = VAL(NCROSS$)
 WEND
 
   Thanks in advance,
         Roger Marquis (marquis@qal.berkeley.edu)

brown@nicmad.UUCP (Vidiot) (04/01/89)

In article <22071@agate.BERKELEY.EDU> marquis@qal.qal.berkeley.edu (Roger Marquis) writes:
<
<     How do you distinguish between a null input string (i.e., 
<the return key) and a zero in QuickBasic? I've tried INKEY$, 
<INPUT and INPUT$. Simply hitting return sets the value at zero
<regardless of initialization or anything else I've tried. I need
<to loop until an integer between zero and nine is entered. Here's 
<where I'm stuck:
<
< NCROSS$ ="" 
< WHILE NCROSS$ = ""
<      CLS : LOCATE 3, 1
<      PRINT "               Input cross pattern:"
<      PRINT : PRINT : PRINT
<      NCROSS$ = INPUT$(1): NCROSS = VAL(NCROSS$)
< WEND

Your problem is that if you are looking for for one of the zero through nine
keys to be pressed, either from the top row, or from the numeric keypad, you
aren't going to find it that way.  Why, because the press of the RETURN key
will give you zero, as well as pressing the zero key.  You need to look for
the ASCII character:


NCROSS$ ="" 
WHILE NCROSS$ < "0" OR NCROSS$ > "9"
     CLS : LOCATE 3, 1
     PRINT "               Input cross pattern:"
     PRINT : PRINT : PRINT
     NCROSS$ = INPUT$(1)
WEND


Try that, it should be better.
-- 
	        harvard\     att!nicmad\
Vidiot            ucbvax!uwvax..........!astroatc!brown
	        rutgers/  decvax!nicmad/
	ARPA/INTERNET: brown%astroatc.UUCP@spool.cs.wisc.edu

hansen@uhura.cs.wisc.edu (Timothy B. Hansen) (04/11/89)

>      How do you distinguish between a null input string (i.e., 
> the return key) and a zero in QuickBasic? I've tried INKEY$, 
> etc...
> 
>  NCROSS$ ="" 
>  WHILE NCROSS$ = ""
>       CLS : LOCATE 3, 1
>       PRINT "               Input cross pattern:"
>       PRINT : PRINT : PRINT
>       NCROSS$ = INPUT$(1): NCROSS = VAL(NCROSS$)
>  WEND
>  
>    Thanks in advance,
>          Roger Marquis (marquis@qal.berkeley.edu)

Base the terminating condition of the loop on the length of the string that
was entered using the LEN() function instead of on the string itself.
INPUT$(n) will not work since it will return to you a string of at least n
characters, and INPUT$(0) is not too useful.  Either INPUT or LINE INPUT
(the latter being exclusively for string variables) will work.  Also, since
you need to run the input loop "at least once" the DO...LOOP structure is a
better choice:

DO
	CLS : LOCATE 3, 1
	PRINT "               Input cross pattern:"
	PRINT : PRINT : PRINT
	LINE INPUT NCROSS$
	NCROSS = VAL(NCROSS$)

LOOP UNTIL LEN(NCROSS$) > 0


	Tim Hansen (hansen@uhura.cs.wisc.edu)