Menu issues

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
knothead1008
Coder
Posts: 10
Joined: Mon Feb 04, 2019 1:22 am

Menu issues

Post by knothead1008 » Thu Feb 21, 2019 5:00 pm

Hi all.

I have a program that has 4 menus. To which normal operation for the end user works fine as is. What I would like to do is create a way for the user to go back to the previous menu if they decide to or if they make a mistake in choice. For the most part I have one menu working. The issue is when I get to menu 3 I can get it to go back, but when it does, I have double menus on one screen and for some reason the app is remembering the user input from the last menu and adding that into the go back menu.

I don't know if that came out clear or not. But if it did not. Please let me know.

Brian.

MikeHawk
Coder
Posts: 16
Joined: Sun Jul 08, 2018 11:23 am

Re: Menu issues

Post by MikeHawk » Tue Feb 26, 2019 9:41 am

I'm not sure I get what you're trying to do, so here's how I do menus as of late:

Each menu is barely more than a bunch of items that the user can select. Each item can either execute a very specific action (save configuration, apply changes, exit program), change a setting (modify the content of a variable), or redirect to another menu. From there, you can just create a one-size-fits-all routine to handle all your menus.

Lately I've been relying on DATA statements to identify menus and their content, even though I recognize that two separate arrays with custom types would be a much more flexible approach: one array for menus and one for items. Each element in the menu array could contain the name of your menu, how many items appear in there, what is the offset of the first item in the array list, and whatnots. The item array would contain each and every item of all your menus, consecutively. They would contain a label to display on screen, and a function string so you know what to do when the user interacts with it (use prefixes or extra fields to code special behaviors like "switch menu" or "change variable", the rest of the string would tell you the menu name to switch to, or the variable name to modify) - the function string can also influence the way the item should be displayed on screen…

If you know how menus are connected (say "Menu1>Menu2>Menu5"), you don't need anything special to "go back" (say you're in Menu5, the "go back" item will simply be programmed to always switch to Menu2). Or you don't, in which case you need to keep track of how menus are browsed (via a string for instance). Currently parsed menu is added to the right of that string, and thus, going back will just delete the last character, returning the user to the new rightmost menu number.

When it comes to "forgetting changes" in-between menus, the simplest way would be to create a set of temporary variables where you write the changes made. All the actual variable must be copied to the temporary set as the user enters the new menu, then, if the user confirms changes upon exit, copy the temporary set to the actual variables you use in your program; if the user ignores, do nothing (the temporary set will be overwritten on next entry to that menu anyway).

Hope that helps.

knothead1008
Coder
Posts: 10
Joined: Mon Feb 04, 2019 1:22 am

Re: Menu issues

Post by knothead1008 » Tue Feb 26, 2019 10:38 pm

Maybe this'll help out.

Code: Select all

108 ' AFTER THE PROGRAM RUNS PRESS "R" TO RUN AGAIN, OR "Q" TO QUIT.
110 CLS : PRINT : PRINT : PRINT : PRINT TAB(27); "Type of Knot"
120 PRINT TAB(25); "1. Casa Knot"
130 PRINT TAB(25); "2. Standard Two Pass Knot"
140 PRINT TAB(25); "3. Standard Three Pass Knot"
150 PRINT TAB(25); "4. Gaucho or Headhunter's Knot"
155 PRINT : PRINT TAB(20); "To end program now hold down  ctrl  press c"
158 PRINT : PRINT TAB(12); "AFTER THE PROGRAM RUNS PRESS R TO RUN AGAIN, OR Q TO QUIT"
160 PRINT : PRINT TAB(24); : INPUT "Choose one of the above "; MA
170 IF MA < 1 THEN 110 ELSE IF MA > 4 THEN 110
180 ON MA GOTO 710, 190, 190, 610
190 CLS : PRINT : PRINT : PRINT TAB(25); "Type of Standard Knot"
200 PRINT TAB(25); "1. Standard Herringbone Knot"
210 PRINT TAB(25); "2. Standard Pineapple Knot"
220 PRINT TAB(25); "3. Standard Pineapple-Sobre Knot (Even Number Parts)"
230 PRINT TAB(25); "4. Semi-Regular Quasi-(Headhunter or Gaucho) Knot"
240 IF MA = 3 THEN PRINT TAB(25); "5. Standard Hood Knot"
250 IF MA = 3 THEN PRINT TAB(25); "6. Standard Horn Knot"
260 PRINT : PRINT TAB(25); : INPUT "Choose one of the above"; MB
270 IF MB < 1 OR MB > 6 THEN 190
280 ON MB GOTO 480, 290, 290, 490, 500, 510
290 CLS : PRINT : PRINT : PRINT TAB(15); "Position of Bight-Boundries for Second Knot"
300 PRINT TAB(25); "1. Bight - Boundary 1--1"
310 PRINT TAB(25); "2. Bight - Boundary 2--2 (Standard Pineapple)"
320 PRINT TAB(25); "3. Bight - Boundary 1--2"
330 PRINT TAB(25); "4. Bight - Boundary 2--1"
340 PRINT : PRINT TAB(25); : INPUT "Choose one of the above"; FI
350 IF FI < 1 OR FI > 4 THEN 290
360 IF MA = 2 THEN 520
370 CLS : PRINT : PRINT : PRINT TAB(15); "Position of Bight - Boundaries for Third Knot"
380 IF FI = 2 OR FI = 1 THEN 440
390 PRINT TAB(25); "1. Bight - Boundary 3--3"
400 PRINT TAB(25); "2. Bight - Boundary 1--3"
410 PRINT TAB(25); "3. Bight - Boundary 3--1"
420 PRINT : PRINT TAB(25); : INPUT "Choose one of the above"; SI
430 IF SI < 1 OR SI > 3 THEN 370 ELSE 520
440 PRINT TAB(25); "1. Bight - Boundary 3--2"
450 PRINT TAB(25); "2. Bight - Boundary 1--2"
460 PRINT TAB(25); "3. Bight - Boundary 2--1"
470 GOTO 420

MikeHawk
Coder
Posts: 16
Joined: Sun Jul 08, 2018 11:23 am

Re: Menu issues

Post by MikeHawk » Wed Feb 27, 2019 1:19 am

Oh that hurts. What you want to do is add an extra item to your list (so the user knows how to go back), and redirect to the previous menu (GOTO the line number that starts with CLS). Like so:

Code: Select all

255 PRINT TAB(25); "0. Go back"
265 IF (MB = 0) THEN 110

335 PRINT TAB(25); "0. Go back"
345 IF (FI = 0) THEN 190
etc.

knothead1008
Coder
Posts: 10
Joined: Mon Feb 04, 2019 1:22 am

Re: Menu issues

Post by knothead1008 » Wed Feb 27, 2019 2:43 pm

Didn't think like that. Thanks so much.

Post Reply