Obviously, you're going to need a menu in your application so here is a short program that displays a simple menu and allows you to select any item. It tells you which item has been selected and it also allows you to use shortcuts, such as Ctrl+a instead of pressing the Menu key and navigating your way through all the items.

Look at the Do...Until loop in the program below. First we use Get to see what key is being pressed and the key code is returned in k%. First we check to see if this is 290 - the menu key. If it is then we call the showmenu: procedure.

This procedure uses mInit to tell the system that we're going to define a new menu. mCard is then used to define each menu. The first string in quotes, "File" in the first mCard line below, defines the title of the menu, and the following strings define the menu items that appear. Following each menu item is the shortcut key.

So, mCard "Help","About",%a in the program below defines a menu with the title Help and About as a menu item on it. The shortcut for About is %a which meansCtrl+a.

Well, actually, this isn't quite the full story. the %a tells the menu item to return the Ascii code of 'a', which is 97. However, if you press Ctrl+a you get the code 1 (and Ctrl+b is 2, Ctrl+c is 3 and so on). This is why the showmenu: procedure returns the menu code minus 96. Think about it!

On final point - why use -%s below? Well, it still means that the Ascii code of 's' is returned (we subtract 96 and get 19, the same as Ctrl+s), but the minus sign mens underline the menu item. It acts as a separator between two groups of menu items.

PROC menu:
Local k%
Print "Press the Menu key and make a selection"
Print "Or Press Ctrl + a letter key"
  If     k%=290 : k%=showmenu: : Endif
  If     k%=15  : Print "Open"
  Elseif k%=19  : Print "Save"
  Elseif k%=1   : Print "About"
    Print "key = ";k%
Until k%=5

PROC showmenu:
mCard "File","Open",%o,"Save",-%s,"Close",%e
mCard "Help","About",%a
Return Menu-96

Back to RAW Computing

  Psion home page