In English: MENU_BAS, a SuperBASIC function that gives a program a one-line menu bar: it takes an array of option names, an array of short descriptions and the number of options, and returns the code of the first letter of the chosen option, or 0 for ESC. Options are selected with the cursor keys or TABULATE/SHIFT TABULATE and ENTER, or by typing an option's first letter. The listing, marked RG-o QL_DOC 88 and based on QL World April 1988, includes a demonstration with seven word-processor style options.
The article below is in French, as printed in QL_DOC n5 (August-September 1988).
Une étape importante lors de la création d’un programme est la conception de l’interface utilisateur. La fonction MENU propose un interface qui simple est très facile d’utilisation pour l’usager.
Elle a la forme suivante:
touche=MENU(tableau_option$,tableau_descrip$,nombre_option)
La variable touche contiendra le code de la première lettre de l’option choisie, si ESC est appuyé alors la touche=0. Avant d’appeler MENU nons devons avoir un tableau contenant les options disponibles et un autre avec une courte description de celles-çi et afin nous disons combien il y a d’options disponibles.
Lorsque que le menu apparait à l’écran, on change d’option soit avec les touches curseurs ( <- & -> ) ou bien avec TABULATE pour aller à droite ou SHIFT TABULATE pour la gauche. En appuyant ENTER lorsqu’on est sur une option, alors celle-çi est sélectionnée, ou bien sur la première lettre d’une option, MENU vérifie si elle correspond bien à une option, si oui le code est retournée, si non un gros BEEP se fait entendre. Il faut bien entendu une première lettre différente pour chaque option!
100 REMark MENU RG-o QL_DOC 88
110 REMark basé sur QL World apr 88
120 :
130 :
140 :
150 DIM x$(7,15) :REMark x$ contient les options du menu
160 DIM xx$(7,20) :REMark xx$ contient les explications des options
170 CLS#1:CLS#2:CLS#0
180 DATA 'Efface','En-tête','Marge','Sauve','Copie','Footer','Justifie'
190 DATA 'Efface le fichiers','Détermine le Header','Détermine les marges'
191 DATA 'Sauve notre travail',"Copie d'un fichier",'Détermine le footer'
192 DATA 'Justifie notre texte'
200 RESTORE 180
210 FOR i=1 TO 7:READ x$(i) :REMark lecture des options
220 FOR i=1 TO 7:READ xx$(i) :REMark lecture des explications
230 :
240 REPeat test
250 option=menu(x$,xx$,7) :REMark appel du menu
260 PRINT#0,option :REMark PRINT le code de l'option choisie
270 END REPeat test
280 :
290 REMark _________________La fonction MENU requiert 3 paramètres
300 REMark option$ -> le nom du tableau contenant les options
310 REMark expli_option$ -> le nom du tableau contenant les explications
320 REMark nbr_options -> nombre d'options dans le menu
330 :
340 DEFine FuNction menu(option$,expli_option$,nbr_options)
350 LOCal loop,touche,prem_let$(nbr_options),lx(nbr_options),temp,temp$
360 OPEN#9,scr_502x12a5x0:BORDER#9,1,2:PAPER#9,0:CLS#9:lx(1)=0
370 OPEN#10,scr_502x12a5x13:BORDER#10,1,2:PAPER#10,0:CLS#10
380 :
390 REMark ______________premières lettres des commandes disponibles
400 REMark plus la position "x" des commandes
410 :
420 INK#9,6
430 FOR loop=1 TO nbr_options
440 prem_let$=prem_let$&option$(loop,1)
450 IF loop>1:lx(loop)=lx(loop-1)+LEN(option$(loop-1))+2
460 PRINT#9,option$(loop);' ';
470 END FOR loop
480 :
490 loop=1:AT#9,0,lx(1):STRIP#9,144:PRINT#9,option$(loop)
500 PRINT#10,xx$(loop)
510 :
520 REPeat menu_sel
530 touche=CODE(INKEY$(-1))
540 SELect touche
560 REMark _______________curseur droite ou TABULATE
570 =200,9:temp=loop:loop=loop+1:IF loop>nbr_options:loop=1
580 AT#9,0,lx(temp):STRIP#9,0:PRINT#9,option$(temp)
590 AT#9,0,lx(loop):STRIP#9,144:PRINT#9,option$(loop)
600 PRINT#10,xx$(loop)
620 REMark _______________curseur gauche ou SHIFT TABULATE
630 =192,253:temp=loop:loop=loop-1:IF loop<1:loop=nbr_options
640 AT#9,0,lx(temp):STRIP#9,0:PRINT#9,option$(temp)
650 AT#9,0,lx(loop):STRIP#9,144:PRINT#9,option$(loop)
660 PRINT#10,xx$(loop)
680 REMark _______________touche ENTER
690 =10:CLS#9:CLS#10:CLOSE#9:CLOSE#10:RETurn CODE(prem_let$(loop))
710 REMark _______________touche ESCAPE retourne "0"
720 =27:CLS#9:CLS#10:CLOSE#9:CLOSE#10:RETurn 0
740 REMark _______________vérifie si la lettre est celle d'une option
750 =32 TO 127
760 IF CHR$(touche) INSTR prem_let$
770 CLS#10:CLOSE#9:CLOSE#10
780 RETurn CODE(prem_let$(CHR$(touche) INSTR prem_let$))
790 ELSE BEEP 5000,45
800 END IF
820 REMark _______________touche non-valide
830 =REMAINDER :BEEP 5000,45
850 END SELect
860 END REPeat menu_sel
870 END DEFine
880 :
890 REMark FIN
900 :
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.