Weekly Qbasic and Qb64 Lesson Topics
April 20, 2024, 04:25:33 am
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 1211 times)
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« 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


Pages: [1]
  Print  
 
Jump to:  

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


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy