Page 1 of 1

Real newbie question

Posted: Sat Nov 22, 2003 6:29 pm
by Mikeg
Hi,
My first qbasic program, and I'm chuffed.
In two or three places I use coding like:-
C$=inkey$
do
loop until c$>< ""
looking for a Y for yes, N for no or E for exit etc.
problem I got is if user enters yes not just Y the next bit of similar coding seems to pick up the E of yes and thingy up the whole thing by exiting.
I would prefer to use inkey$ rather than input$.
Is there a way of clearing the buffer just before the inkey$ statement.
Thanks for your time guys.

MikeG

Hi there...

Posted: Sun Nov 23, 2003 1:35 am
by Dr_Davenstein
This is the problem...

loop until c$>< ""

That will exit the loop if any key is pressed...
Also, there is no need to clear the buffer each time through the loop because the next call to inkey$ replaces what's stored in the buffer C$.
Another thing...
You need to call INKEY$ from inside the DO...LOOP statement block.

This is one solution...

Code: Select all

DO 
 C$ = UCASE$(INKEY$ )
LOOP UNTIL C$ = "E" 
The UCASE$ function returns UpperCASE characters &nbsp;no matter what. In contrast, the LCASE$ function returns LowerCASE characters.

Here's an example...

Code: Select all

MyName$ = "dave"
PRINT UCASE$(MyName$)
Hopefully this clears things up a bit for you. &nbsp; ;D