Qbasicnews.com
September 28, 2021, 01:35:53 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: General Problems  (Read 3931 times)
EclipseOTO
New Member

Posts: 17


« on: July 02, 2006, 01:02:43 PM »

Hey, it's me again! I have a somewhat lesser and unimportant problem that in no way will have a big problem in the final program, as I have an alternative way that works. So here's the lowdown on what I would like this section of the program to do: I would like the program to display the menu with one of the selections highlighted in blue. When you press an arrow key, in order to bring up the menu, the menu comes up with the first option highlighted as it should be. However from that point on when I try to use the arrow keys to change the selection it simply remains the same screen!

Here is the code:
Code:

Menu1: WHILE INKEY$ = ""
WEND
Key$ = INKEY$
IF Key$ = CHR$(0) + CHR$(72) THEN LET menu% = menu% - 1
IF menu% = 0 THEN LET menu% = 1
IF Key$ = CHR$(0) + CHR$(80) THEN LET menu% = menu% + 1
IF menu% = 6 THEN LET menu% = 5
     
IF Key$ = CHR$(0) + CHR$(77) THEN GOTO selection

CLS
COLOR 4, 0, 0
PRINT "Spanish Helper Version 1.1"
COLOR 7, 0, 0
IF menu% = 1 THEN COLOR 7, 1, 0 ELSE COLOR 7, 0, 0
PRINT "1) Origin"
IF menu% = 2 THEN COLOR 7, 1, 0 ELSE COLOR 7, 0, 0
PRINT "2) Continue"
IF menu% = 3 THEN COLOR 7, 1, 0 ELSE COLOR 7, 0, 0
PRINT "3) Data wipe"
IF menu% = 4 THEN COLOR 7, 1, 0 ELSE COLOR 7, 0, 0
PRINT "4) Reference"
IF menu% = 5 THEN COLOR 7, 1, 0 ELSE COLOR 7, 0, 0
PRINT "5) Exit"
PRINT Key$
PRINT "Poopy Toopy"
GOTO Menu1

selection: IF menu% = 1 THEN GOTO origin
IF menu% = 2 THEN GOTO writer
IF menu% = 3 THEN GOTO wipe
IF menu% = 4 THEN GOTO ref
IF menu% = 5 THEN END



thanks for any help you can give!
EclipseOTO
Logged
Anonymous
Guest
« Reply #1 on: July 02, 2006, 02:20:57 PM »

seems you're clearing your inkey buffer before keys can be read... try this:

Code:

Menu1:
do
Key$ = INKEY$
loop while key$ = ""
IF Key$ = CHR$(0) + CHR$(72) THEN LET menu% = menu% - 1
IF menu% = 0 THEN LET menu% = 1
IF Key$ = CHR$(0) + CHR$(80) THEN LET menu% = menu% + 1
IF menu% = 6 THEN LET menu% = 5
     
IF Key$ = CHR$(0) + CHR$(77) THEN GOTO selection

CLS
COLOR 4, 0, 0
PRINT "Spanish Helper Version 1.1"
COLOR 7, 0, 0
IF menu% = 1 THEN COLOR 7, 1, 0 ELSE COLOR 7, 0, 0
PRINT "1) Origin"
IF menu% = 2 THEN COLOR 7, 1, 0 ELSE COLOR 7, 0, 0
PRINT "2) Continue"
IF menu% = 3 THEN COLOR 7, 1, 0 ELSE COLOR 7, 0, 0
PRINT "3) Data wipe"
IF menu% = 4 THEN COLOR 7, 1, 0 ELSE COLOR 7, 0, 0
PRINT "4) Reference"
IF menu% = 5 THEN COLOR 7, 1, 0 ELSE COLOR 7, 0, 0
PRINT "5) Exit"
PRINT Key$
PRINT "Poopy Toopy"
GOTO Menu1

selection: IF menu% = 1 THEN GOTO origin
IF menu% = 2 THEN GOTO writer
IF menu% = 3 THEN GOTO wipe
IF menu% = 4 THEN GOTO ref
IF menu% = 5 THEN END
Logged
EclipseOTO
New Member

Posts: 17


« Reply #2 on: July 02, 2006, 02:28:08 PM »

nice! It works great now!  I'm pretty unclear on the whole inkey$ usage, can you explain why my code didn't work or give me a good link that explains inkey maybe?

Thanks,
EclipseOTO

EDIT: I forgot to add, is there a code for the "Enter" key?  I can't seem to find it!
Logged
Anonymous
Guest
« Reply #3 on: July 02, 2006, 02:58:35 PM »

enter = chr$( 13 ), i believe...

the way inkey works is, when you hit a key, it is stored in the inkey buffer. when you call inkey, it spits out the keys that you pressed. FIFO (first in, first out).

in your program, the majority of the loop execution is spent below the while...wend. so that means that you're most likely to be in that point when you hit the keys. well, say you hit an arrow key, then, when you'd get to your while...wend, it would completely clean out the inkey buffer, until nothing was left, before it would allow execution to pass. then you would have nothing in your key$ variable, you see? =)
Logged
EclipseOTO
New Member

Posts: 17


« Reply #4 on: July 02, 2006, 05:55:07 PM »

ah, okay that makes sense, thanks a lot!

EDIT:  I've experimented a bit with the Inkey$ function and ran into the problem of in the beginning of my program, which has several sleep functions to delay the program, if enter is pressed multiple times I think it goes into the buffer multiple times.  This wreaks havoc with the program and I was wondering if there was a way to clear the buffer without pausing the program!
Logged
Anonymous
Guest
« Reply #5 on: July 03, 2006, 02:16:53 AM »

sleep is a very unreliable mechanism for delaying a program (in qb. in fb you have SLEEP 2000, 1, which sleeps 2 seconds, and ignores all key input).

try something like this


Code:
dim timerDelay as double

timerDelay = TIMER + 2 '' I want to wait 2 seconds

do
loop until TIMER > timerDelay


for a reliable delay ^^
Logged
EclipseOTO
New Member

Posts: 17


« Reply #6 on: July 04, 2006, 12:18:05 AM »

thanks for the more reliable timer, however this doesn't fix my problem.  The problem is in the delayed sequence in which I'm using the timer if the enter key is pressed multiple times, when the program reaches the menu, it registers the enter as many times as it was pressed during the delayed sequence.  Is there a way to clear this or change the program or something?
Logged
RyanKelly
Forum Regular
**
Posts: 109



WWW
« Reply #7 on: July 04, 2006, 12:35:26 AM »

Quote from: "EclipseOTO"
thanks for the more reliable timer, however this doesn't fix my problem.  The problem is in the delayed sequence in which I'm using the timer if the enter key is pressed multiple times, when the program reaches the menu, it registers the enter as many times as it was pressed during the delayed sequence.  Is there a way to clear this or change the program or something?


Use a loop like this to clear the keyboard buffer before displaying the menu.

do while not (inkey$="")
loop
Logged
anarky
Been there, done that
*****
Posts: 1231


The Blobworld Comics King


« Reply #8 on: July 04, 2006, 10:32:32 AM »

I didn't know that one... So simple...
Logged

Screwing with your reality since 1998.
EclipseOTO
New Member

Posts: 17


« Reply #9 on: July 04, 2006, 01:14:45 PM »

Is there a way I can use that sort of loop without requiring the user to press a key to continue with the program?
Logged
anarky
Been there, done that
*****
Posts: 1231


The Blobworld Comics King


« Reply #10 on: July 04, 2006, 01:19:50 PM »

You can have a OR situation. Add a time limit to press a key based on TIMER. The program can continue if a key is pressed or the timer runs out, whichever comes first.
Logged

Screwing with your reality since 1998.
Anonymous
Guest
« Reply #11 on: July 04, 2006, 02:15:43 PM »

Um, the loop ryankelly posted does not require a key to be pressed. It simply loops until the buffer is clean.
Logged
EclipseOTO
New Member

Posts: 17


« Reply #12 on: July 04, 2006, 10:59:17 PM »

Quote from: "cha0s"
Um, the loop ryankelly posted does not require a key to be pressed. It simply loops until the buffer is clean.

Oops, my fault entirely, I just noticed a misplaced sleep funtion that was causing that to happen!  Thanks a lot, this works great!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!