im trying to make a menu for a program im making and i would like to use the down and up keys to navigate but i dont know how to use them , so could anyone show me how to use them?
You can tell what most keys that have been pressed are by using INKEY$. The "printable" keys give a single ASCII character code . These can be found ASCII Character set table in QBasic help.
A whole collection of characters also give a ASCII code from INKEY$. These aren't listed in the help but are two characters long. The first character is always CHR%(0). You can test for them by using
LOOP UNTIL INKEY$ <> ""
IF INKEY$ = CHR$(0) + CHR$(72) THEN .....
Here's a short list of some you'd make most use of
Up arrow ---- CHR$(0) + CHR$(72)
Down arrow -- CHR$(0) + CHR$(80)
Left arrow -- CHR$(0) + CHR$(75)
Right arrow - CHR$(0) + CHR$(77)
Don't forget if NUMLOCK is off then 4 on the keypad will give the same as the left arrow, CHR$(0) + CHR$(75). If NUMLOCK is on it will give the code for 4 which is CHR$(52)
The PageUp, PageDown, Insert, Delete, Del keys etc all have their own codes.
At the risk of boring everyone to death, I've written some programs that you may like to look at. Here is a short program that will give you the codes for all the keys that return them
'KBRDCODE Ray Thomas June 2000
'A program to show the codes returned by the keyboard on a keypress
Count = 0
IF Count MOD 20 = 0 THEN GOSUB Titles
UserIn$ = INKEY$
LOOP UNTIL UserIn$ <> ""
PRINT LEN(UserIn$); TAB(10); LEFT$(UserIn$, 1); TAB(20); ASC(UserIn$)
IF LEN(UserIn$) = 2 THEN
UserIn$ = RIGHT$(UserIn$, 1)
LOCATE CSRLIN - 1, 30
PRINT UserIn$; TAB(40); ASC(UserIn$)
Count = Count + 1
LOOP UNTIL UserIn$ = CHR$(27)
PRINT TAB(10); "Characteristics of UserIn$"
PRINT "Length"; TAB(10); "1st Char"; TAB(20); "Asc"; TAB(30); "2nd Char"; TAB(40); "ASC"
It can also be downloaded from
I hope this is of use to you.
ok i got it so i can move up and down in my menu, but now i want to be able to hit enter and it will send me to the part of my program assosiated with whatever choice they choose.
The way I do it is to keep a count of where in the menu the cursor, or high-lighted choice is. "Up" decreases the count, "Down" increases it. From the "count" you should be able to work out which element in the menu the user wants.
This is particularly easy to do if the menu items are kept in an array. Even easier if the the first choice in the menu is 1 and OPTION BASE 1 is in the program.
From my previous post you'll find that Enter = CHR$(13), and to enable the user to get out of the menu without making a choice Esc = CHR$(27)
Without writing it for you, which wouldn't be very helpful to you, the bones of the program should look like :-
Draw the menu with the highlighted choice (if this is the first time then HiLite = 1)
Get the user input
LOOP UNTIL input = CHR$(13) or CHR$(27)
IF input = CHR$(13) THEN the chosen menu item = HiLite
If you get REALLY REALLY stuck, then I've got 5 example menu programs on my website, but you'll learn faster and better if you try and write this yourself. Even if you make mistakes while writing the program you'll still be learning what the language can and can't do.
I've just replied to you, but the message seems to have gone to byte heaven. So here it is again.
I think I may have mis-read what you wanted. Here's how to send your users on there way to the depths of your program, away from the menu.
Once they've made their choice you can use IF or SELECT CASE statements.
IF MenuChoice = 1 THEN (gosub) Choice1
IF MenuChoice = 2 THEN (gosub) Choice2
SELECT CASE MenuChoice
SELECT can do a bit more than that but you can look it up the help file.
Some programmers say you should always use SELECT instead of IF statements where you can, they generally run faster and look tidier. You'd have to be superhuman to notice any difference in speed though.
Another thing to think about is how you want people to get back to the menu if they need to.
It looks like you're new here. If you want to get involved, click one of these buttons!
Assembly Code Share
Getting started in assembly
C and C++
C/C++ on Linux/Unix
C/C++ Windows API
C++ Game Development
Delphi and Kylix
Java Server Pages
Access databases and VB
Advance Visual Basic
DirectX Game dev
Newbie Game Programmers
Cooling & Overclocking
Database & SQL
Sound & Music
FreeLance Software City
C# & VB.NET School Support
Join the Team
Comments on this site
New programming languages
Off topic board
Mobile & Wireless
Operating Systems & Platforms
Witsbits Go Cloud
Embedded / RTOS
Windows CE & Pocket PC
Networking And Security
Windows 2003 Server
RUP & UML
Quality & Testing
Active Server Pages
HTML & WEB-Design
Mobile Internet & Messaging
WEB-Services / SOAP
In this Discussion