Weekly Qbasic and Qb64 Lesson Topics
January 21, 2018, 12:50:57 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

Menus and Choices


Pages: [1]
  Print  
Author Topic: Menus and Choices  (Read 577 times)
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« on: March 31, 2011, 12:04:09 am »

A discussion, answering a question, on make a prgarm with a menu, for 6 choices, started in the general discussion category, is my motive for starting this topic.
from Garry
Report Spam   Logged

Social Buttons

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #1 on: March 31, 2011, 12:17:25 am »

Taken from:
http://weeklyqbasicandqb64lesson.smfforfree.com/index.php/topic,115.0.html
 Below are some code samples,
Code:
REM Code posted by Oldoslover
DEFINT A-Z 'make all variables integers

SCREEN 12 '640 x 480 pixel at 16 colors

SelectionArea$ = STRING$(20, 220) 'create 20 characters of a square into a string
Done = 0 'our master exit variable
OOption = 1 'our menu idenitifyer

PRINT "Use the UP and DOWN arrow keys to move highlight bar up and down , enter key to select that selection"
PRINT "Any key to contimue"
Dummy$ = INPUT$(1) 'wait for keypress
CLS 'clear the screen

GOSUB Drawmenu 'draw the menu
GOSUB Highlight 'draw the highlight
DO

  IF _KEYDOWN(20480) THEN 'down arrow key
    OOption = OOption + 1 'increment selection variable
    IF OOption = 7 THEN OOption = 1 'if variable at end of list wrap it around to start of list
    CLS
    GOSUB Drawmenu
    GOSUB Highlight
    _DELAY .5 'delay to stop too fast movement
  END IF

  IF _KEYDOWN(18432) THEN 'up arrow key
    OOption = OOption - 1
    IF OOption = 0 THEN OOption = 6
    CLS
    GOSUB Drawmenu
    GOSUB Highlight
    _DELAY .5
  END IF

  IF _KEYDOWN(13) THEN 'enter key
    LOCATE 28, 20: PRINT "Now going to MENU "; OOption
    Done = 1 'toggle exit variable
  END IF

LOOP WHILE Done = 0
SLEEP
SYSTEM

'------------------------
Drawmenu:
menuid = 1
FOR t = 10 TO 20 STEP 2
  LOCATE t, 30: PRINT menuid
  menuid = menuid + 1
NEXT t
RETURN

Highlight:
SELECT CASE OOption
  CASE 1
    LOCATE 10, 32: PRINT SelectionArea$
  CASE 2
    LOCATE 12, 32: PRINT SelectionArea$
  CASE 3
    LOCATE 14, 32: PRINT SelectionArea$
  CASE 4
    LOCATE 16, 32: PRINT SelectionArea$
  CASE 5
    LOCATE 18, 32: PRINT SelectionArea$
  CASE 6
    LOCATE 20, 32: PRINT SelectionArea$
END SELECT
RETURN
More Code, Dusty (below)
Code:
DIM SHARED Llist$(10)
DIM SHARED Sel AS INTEGER

SCREEN 12

FOR x = 1 TO 10 '---- Get the Menu List - Only needs done once
   READ Llist$(x)
NEXT x

MakeMenu '---- Show the Menu

'----------------

DO
   '--- Moving down Menu
   IF _KEYDOWN(20480) THEN
      COLOR 0, 7 ' --- Erase last move
      LOCATE Sel, 25: PRINT Llist$(Sel - 5)

      Sel = Sel + 1: IF Sel > 15 THEN Sel = 6
      COLOR 0, 8 ' --- Show present move going down
      LOCATE Sel, 25: PRINT Llist$(Sel - 5)
   END IF

   ' --- Moving up the Menu
   IF _KEYDOWN(18432) THEN
      COLOR 0, 7 ' --- Erase last move
      LOCATE Sel, 25: PRINT Llist$(Sel - 5)

      Sel = Sel - 1: IF Sel < 6 THEN Sel = 15
      COLOR 0, 8 ' ---  Show present move going up the Menu
      LOCATE Sel, 25: PRINT Llist$(Sel - 5)
   END IF

   a$ = INKEY$
   IF a$ = CHR$(13) THEN '--- press ENTER to select
      Selection Sel ' ---  Goto Selected item
   END IF


   IF LCASE$(a$) = "q" THEN EXIT DO ' --- end Program

   _DISPLAY
   _LIMIT 8 ' --- set speed of selecter, change if selecter goes to fast or slow. Large number = faster
LOOP

SYSTEM

'-------------- Change these suit your needs in the menu ----------------
DATA "Math","Draw Circle","Draw Box","Enter Name","Paste","Clear","Cut","Find","New","Run"

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' _____________________ Sub Selection _________________________________
SUB Selection (Sel)
GotoRoutine = Sel - 5


' NOTE:  cases 1 to 3 are calling subs. I didn't use subs in Cases  4 to 10
'            You can choose to do it either way but subs seperate from the rest
'            so its easier to edit later on and makes the programs more clear.

SELECT CASE GotoRoutine

   CASE 1
      Math ' --- Call sub math

   CASE 2
      DrawCircle ' --- Call sub DrawCircle

   CASE 3
      Drawbox ' --- Call sub Drawbox

   CASE 4
     
      COLOR 0, 7: CLS: LOCATE 10, 20
      INPUT "What is your name?"; n$,
      LOCATE 12, 20: PRINT "Hello "; n$; " Press a key to go to menu"
      _DISPLAY
      SLEEP 'wait for keypress to leave sub
      DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

   CASE 5
      COLOR 0, 7: CLS: LOCATE 10, 20
      PRINT "you selected Option 'PASTE', Press a key to go to menu";
      _DISPLAY
      SLEEP 'wait for keypress to leave sub
      DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

   CASE 6
      COLOR 0, 7: CLS: LOCATE 10, 20
      PRINT "you selected Option Clear, Press a key to go to menu";
      _DISPLAY
      SLEEP 'wait for keypress to leave sub
      DO: LOOP UNTIL INKEY$ = "" '  clear the keyboard after SLEEP statement

   CASE 7
      COLOR 0, 7: CLS: LOCATE 10, 20
      PRINT "you selected Option 'CUT', Press a key to go to menu";
      _DISPLAY
      SLEEP 'wait for keypress to leave sub
      DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

   CASE 8
      COLOR 0, 7: CLS: LOCATE 10, 20
      PRINT "you selected Option 'FIND', Press a key to go to menu";
      _DISPLAY
      SLEEP 'wait for keypress to leave sub
      DO: LOOP UNTIL INKEY$ = "" '  clear the keyboard after SLEEP statement

   CASE 9
      COLOR 0, 7: CLS: LOCATE 10, 20
      PRINT "you selected Option 'NEW', Press a key to go to menu";
      _DISPLAY
      SLEEP 'wait for keypress to leave sub
      DO: LOOP UNTIL INKEY$ = "" '  clear the keyboard after SLEEP statement

   CASE 10
      COLOR 0, 7: CLS: LOCATE 10, 20
      PRINT "you selected Option 'RUN', Press a key to go to menu";
      _DISPLAY
      SLEEP 'wait for keypress to leave sub
      DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

END SELECT

MakeMenu '-------- Go back to the menu
END SUB

' _______________________ Sub Draw Circle _________________________________
SUB DrawCircle

COLOR 0, 7: CLS '------- Clear the screen of the menu
CIRCLE (300, 100), 50, 4
LOCATE 14, 20
PRINT " we are drawing circles"
LOCATE 16, 20
PRINT " Press a key to go back to main menu"

_DISPLAY ' -- show the circle and text

SLEEP 'wait for keypress to leave sub
DO: LOOP UNTIL INKEY$ = "" '  clear the keyboard after SLEEP statement

END SUB

'_______________________ Sub Draw Box_________________________________
SUB Drawbox

COLOR 0, 7: CLS ' ------- Clear the screen of the menu
LINE (200, 100)-(400, 150), 4, BF
LINE (200, 100)-(400, 150), 0, B
LOCATE 14, 20
PRINT " we are drawing boxes"
LOCATE 16, 20
PRINT " Press a key to go back to main menu"

_DISPLAY ' --- show the box and text

SLEEP 'wait for keypress to leave sub
DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

END SUB
'______________________ Sub Math _____________________________________
SUB Math

COLOR 0, 7: CLS ' ------- Clear the screen of the menu
LOCATE 10, 16
PRINT " we are doing math now:  9 X 6 = 54"
LOCATE 12, 10
PRINT " Put your Multiplication tables in this Sub Routine 'Math'"
LOCATE 16, 18
PRINT "Press a key to go back to the main menu"
_DISPLAY ' ------- Show the text

SLEEP
DO: LOOP UNTIL INKEY$ = "" ' clear the keyboard after SLEEP statement

END SUB

'_________________ Sub Make the Menu ________________________
SUB MakeMenu
Sel = 6 ' --- Start location for selecter

COLOR 0, 7: CLS
FOR x = 5 TO 15 ' ---  Print the Menu list
   LOCATE x, 25
   PRINT Llist$(x - 5)
NEXT x

LOCATE 20, 10
PRINT "Use up/Down arrow keys - Press Enter to make selection";
LOCATE 22, 20: PRINT " Press q to exit";
COLOR 0, 8: LOCATE Sel, 25
PRINT Llist$(Sel - 5)
_DISPLAY

END SUB 

Guess thats about it, I did not copy all of the original posts, nor code, to see all that use the link at the top.
 Any one wanting to add, examples, or has questions, or explanations,...feel free to continue adding to this interesting topic.
from Garry
Report Spam   Logged

OlDosLover
Guest
« Reply #2 on: April 03, 2011, 09:31:46 am »

Hi all,
    Here is a simple QB64 adjustable length (a-z) alphabetical menu.
Code:
REM
DIM Alltitles$(26)
SCREEN 12
GOSUB Makmenu
GOSUB Showmenu

DO
  _LIMIT 30
  IF _KEYDOWN(97) THEN GOSUB aMenu
  IF _KEYDOWN(98) THEN GOSUB bMenu
  IF _KEYDOWN(99) THEN GOSUB cMenu
  IF _KEYDOWN(100) THEN GOSUB dMenu
  IF _KEYDOWN(101) THEN GOSUB eMenu
  IF _KEYDOWN(102) THEN GOSUB fMenu
  IF _KEYDOWN(103) THEN GOSUB gMenu
  IF _KEYDOWN(104) THEN GOSUB hMenu
  IF _KEYDOWN(105) THEN GOSUB iMenu
  IF _KEYDOWN(106) THEN GOSUB jMenu
  IF _KEYDOWN(107) THEN GOSUB kMenu
  IF _KEYDOWN(108) THEN GOSUB lMenu
  IF _KEYDOWN(109) THEN GOSUB mMenu
  IF _KEYDOWN(110) THEN GOSUB nMenu
  IF _KEYDOWN(111) THEN GOSUB oMenu
  IF _KEYDOWN(112) THEN GOSUB pMenu
  IF _KEYDOWN(113) THEN GOSUB qMenu
  IF _KEYDOWN(114) THEN GOSUB rMenu
  IF _KEYDOWN(115) THEN GOSUB sMenu
  IF _KEYDOWN(116) THEN GOSUB tMenu
  IF _KEYDOWN(117) THEN GOSUB uMenu
  IF _KEYDOWN(118) THEN GOSUB vMenu
  IF _KEYDOWN(119) THEN GOSUB wMenu
  IF _KEYDOWN(120) THEN GOSUB xMenu
  IF _KEYDOWN(121) THEN GOSUB yMenu
  IF _KEYDOWN(122) THEN GOSUB zMenu
  GOSUB Showmenu

LOOP UNTIL _KEYDOWN(27)
SYSTEM


DATA "Title1"
DATA "Title2"
DATA "Title3"
DATA "Title4"
DATA "Title5"
DATA "Title6"
DATA "Title7"
DATA "Title8"
DATA "Title9"
DATA "Title10"
DATA "Title11"
DATA "Title12"
DATA "Title13"
DATA "Title14"
DATA "Title15"
DATA "Title16"
DATA "Title17"
DATA "Title18"
DATA "Title19"
DATA "Title20"
DATA "Title21"
DATA "Title22"
DATA "Title23"
DATA "Title24"
DATA "Title25"
DATA "Title26"


Makmenu:
FOR a = 0 TO 25
  READ a$
  Alltitles$(a) = a$
NEXT a
a$ = ""
RETURN

Showmenu:
FOR a = 0 TO 25
  LOCATE a + 1, 10
  PRINT CHR$(97 + a); "  "; Alltitles$(a)
NEXT a
RETURN

aMenu:
CLS
_DELAY 1
RETURN

bMenu:
CLS
_DELAY 1

RETURN

cMenu:
CLS
_DELAY 1

RETURN

dMenu:
CLS
_DELAY 1

RETURN

eMenu:
CLS
_DELAY 1

RETURN

fMenu:
CLS
_DELAY 1

RETURN

gMenu:
CLS
_DELAY 1

RETURN

hMenu:
CLS
_DELAY 1

RETURN

iMenu:
CLS
_DELAY 1

RETURN

jMenu:
CLS
_DELAY 1

RETURN

kMenu:
CLS
_DELAY 1

RETURN

lMenu:
CLS
_DELAY 1

RETURN

mMenu:
CLS
_DELAY 1

RETURN

nMenu:
CLS
_DELAY 1

RETURN

oMenu:
CLS
_DELAY 1

RETURN

pMenu:
CLS
_DELAY 1

RETURN

qMenu:
CLS
_DELAY 1

RETURN

rMenu:
CLS
_DELAY 1

RETURN

sMenu:
CLS
_DELAY 1

RETURN

tMenu:
CLS
_DELAY 1

RETURN

uMenu:
CLS
_DELAY 1

RETURN

vMenu:
CLS
_DELAY 1

RETURN

wMenu:
CLS
_DELAY 1

RETURN

xMenu:
CLS
_DELAY 1

RETURN

yMenu:
CLS
_DELAY 1

RETURN

zMenu:
CLS
_DELAY 1

RETURN

Obviously you can edit the data statements to reflect the title you desire. You slot your code into the referenced menu gosubs.
OlDosLover.
Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #3 on: April 03, 2011, 11:17:04 am »

Thanks Oldoslover, this is a easy way to do a menu, it looks like.
from Garry
Report Spam   Logged

OlDosLover
Guest
« Reply #4 on: April 03, 2011, 11:34:37 am »

Hi all,
    Ironically this was written for a member of another site that posts incessantly new programs that could be incorporated in some structure like this. The purpose would be to stop the clutter of extremely similar programs and make it easier to compare individual programs. Guess who?
OlDosLover.
Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #5 on: April 03, 2011, 12:21:12 pm »

Thats a interesting way to use this, I had been thinking the same, for when I had several "mini" programs, to open them, ....
from Garry
I have something I am going to post in off topic...
from Garry
Report Spam   Logged


Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Buy traffic for your forum/website
traffic-masters
Powered by SMF | SMF © 2016, Simple Machines