|
Post by ffgandalf on May 15, 2005 17:52:04 GMT -5
In the file MENU.bas how do you insert diffrent actions besides naming what you selected after selecting a menu option?
|
|
|
Post by brisray on May 15, 2005 23:22:16 GMT -5
Good question. Almost all the menus on that page use a variable named ChooseItem, except for hmenu.bas where I've named it HiLiteItem for some reason, so the following techniques will work for all the menus - that's forward thinking!
Look for this variable somewhere near the top of the program in the line PRINT "Item chosen ="; MenuItem(ChooseItem), just before the END statement.
What happens is that the program will print the value of Array(ChooseItem) then exit the program. All you need do is use an IF or SELECT CASE statement to test for the value of ChooseItem then take some action on that value.
An IF statement example would be...
IF ChooseItem = 3 THEN .... IF ChooseItem = 4 THEN ....
Where you would jump to another subroutine or carry out some other code.
An example for SELECT CASE would be...
SELECT CASE ChooseItem CASE 1 .... CASE 2 .... CASE ELSE .... END SELECT
From the subroutine that is called you can either retuen back to the drawmenu subroutine (SUB DrawMenu) or do what I think is the better way and use the method I used in hmenu.bas where the menu will repeat until the user actually exits the menu program altogether...
DO GOSUB DrawMenu '*** Draw the menu *** GOSUB UserInput '*** Get the user input ***
LOOP UNTIL UserIn$ = CHR$(27)
Or you could use Exit Program as one of the menu choices so the lines would read...
DO GOSUB DrawMenu '*** Draw the menu *** GOSUB UserInput '*** Get the user input ***
LOOP UNTIL UserIn$ = CHR$(27) OR ChooseItem = 8
Where item 8 in the array is to exit the program. Well written programs would check that the user actually wanted to exit the program as in the message "Are you sure?" or whatever.
I hope the above makes sense, if you'd like more help then either email me - brisray@yahoo.co.uk - or just post back here and I'll try t explain it a little differently and maybe re-write one of the programs to show you exactly what to do.
Ray
|
|
|
Post by ffgandalf on May 16, 2005 15:27:03 GMT -5
Thank you
|
|