Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!schaefer!uhura!hansen From: hansen@uhura.cs.wisc.edu (Timothy B. Hansen) Newsgroups: comp.sys.ibm.pc Subject: Re: QBasic null input query Summary: Q-BASIC, null inputs Message-ID: <167@uhura.cs.wisc.edu> Date: 10 Apr 89 20:32:42 GMT References: <22071@agate.BERKELEY.EDU> Organization: Undergraduate Projects Laboratory, University of Wisc. - Madison Lines: 36 > 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)