mmbasic:psmenu_simple_menu_to_select_a_menu_item
psmenu - simple menu to select a menu item
' MMBasic DOS 5-04-05 Beta 7 ' psmenu - version 1 ' by Peter Svard , 2017.09.22 ' Show how to use psmenu Sub (and psmenuinit) Colour 7,0 Cls ' setup variables for psmenu Const psmmax = 10 ' max menu items Dim psmt(psmmax) As string ' create menu array Dim eKey As integer ' return eKey-code Dim mindex As integer ' return menu index ' notes: change menutext using Sub psmenuinit Cursor 3,2:Print "psmenu Use cursor Up or Down to move. Press Enter or ESC to exit." psmenu 3,5,7,0,eKey,mindex Cursor 0,18 Print " Return code from psmenu " Print " menu index = ";mindex Print " exit eKey = ";eKey End ' ----- psmenu ----- ' col,row = menu position ' fc,bc = colour foreground, background ' eKey = return key ( 13=Enter, 27=ESC-key) ' mindex = return menu index Sub psmenu(col As integer,row As integer,fc As integer,bc As integer, eKey As integer, mindex As integer) psmenuinit Local i As integer Local t As integer ' inkey$ key-code ' print out the menu Colour fc,bc For i=0 To psmmax-1 Cursor col,row+i Print psmt(i+1) Next i i = 0 ' start at first menu item (0=first item) Colour bc,fc ' show menu cursor Cursor col,row+i Print psmt(i+1); ' main menu loop start Do t=Asc(Inkey$) ' wait for a Key If t=13 Or t=27 Then ' Enter or ESC-key eKey=t ' return eKey-code mindex=i+1 ' return menu index Exit Do End If If t=128 Or t=129 Then ' cursor Up or Down Colour fc,bc ' clear menu cursor Cursor col,row+i Print psmt(i+1) If t=128 And i>0 Then i=i-1 ' Up If t=129 And i<psmmax-1 Then i=i+1 ' Down Colour bc,fc ' show menu cursor Cursor col,row+i Print psmt(i+1); End If Loop Colour 7,0 ' return to default colour End Sub Sub psmenuinit() ' add menu text here psmt(1)=" 1. menu item one " psmt(2)=" 2. menu item two " psmt(3)=" 3. menu item three " psmt(4)=" 4. menu item four " psmt(5)=" 5. menu item five " psmt(6)=" 6. menu item six " psmt(7)=" 7. menu item seven " psmt(8)=" 8. menu item eight " psmt(9)=" 9. menu item nine " psmt(10)=" 10. menu item ten " End Sub
mmbasic/psmenu_simple_menu_to_select_a_menu_item.txt · Last modified: 2024/03/01 10:39 by gerry