Real newbie question

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Mikeg
Newbie
Posts:1
Joined:Sat Nov 22, 2003 6:10 pm
Location:Scotland
Real newbie question

Post by Mikeg » Sat Nov 22, 2003 6:29 pm

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

Dr_Davenstein
QBasic God
Posts:166
Joined:Tue Mar 25, 2003 12:45 am
Location:U.S.A.
Contact:

Hi there...

Post by Dr_Davenstein » Sun Nov 23, 2003 1:35 am

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
Come check out [url=http://www.freebasic.net/forum/index.php]FreeBASIC[/url]. The syntax is based on QuickBasic, but it expands to use pointers, operator overloading, etc... The list goes on and on!

Post Reply