Creating user friendly programs (4) ----------------------------------- by Steven Flintham (15A) ------------------------ Interacting with the user (1) ----------------------------- An extremely important part of any userfriendly program is the way in whichthe user and program interact with oneanother. There are a variety of techniquesavailable, such as: The WIMP approach ----------------- WIMP (Windows, Icons, Menus & Pointers)systems have become extremely commonthese days and have been around forsome time now. The first real system ofthis kind on the BBC series was AMXArt, which was released around April1985, if I remember correctly.Implementing a system of this standardon a machine with just 32k isdifficult, and for many purposes notnecessary - even if you have the AMXROM which makes this type ofprogramming easier, a large amount ofRAM is still taken up by the controlroutines and data storage necessary.However, anyone who has used a PC willprobably have come across the "text-based" type WIMP system which is oftenused - I think the PCPlus cover discmenu uses this system. This should beperfectly possible on the BBC serieswithout too much trouble, and I mightcover it later in this series. The command line approach ------------------------- Always fairly rare in applications,this is the type of interaction used byMS-DOS and similar operating systems.View's command menu is also an exampleof this type of user interface. Thesesystems are fairly user un-friendly byvirtue of their approach, although thisisn't always a problem, as it can haveadvantages for experienced users interms of speed and flexibility. The menu approach ----------------- This is what I intend to cover (atleast partly) in this article. Thereare several different types of menu butthey can be subdivided into two maincategories - direct choice menus and"step selection" menus. Direct choice menus are those where theuser directly enters a code of somesort representing the option theyrequire. The 8BS menu is a good exampleof this type, although it is slightlyunusual in the three digit codes usedto select menu options. "Step selection" menus are those whereone option is highlighted and, by somemeans or another, the user stepsthrough the options which are thenhighlighted in turn. The highlightedoption can then be chosen in some way.The 8BS software menu is of this type. There is also a variant on the stepselection method which provides keyshortcuts (often called hot keys) forsome of the menu options, which canthen be chosen with a single keypress.This allows the additional userfriendliness of the step selectionmethod with the speed of the directentry method, at the cost of a littleextra programming. Implementing direct choice menus -------------------------------- Direct choice menus are extremely easyto implement and require relativelylittle program code to produce them.They are therefore ideal if you want totry to use as little memory aspossible. Their ease of implementationalso makes them useful if you are in ahurry - perhaps when writing the firstversion of a program, when you want toget on with the main part of the codebut need a menu structure to fit ittogether with. In a user-friendly program, it isimportant that the menu should be welllaid out. The style is up to you - youmay find some of the previous articlesin this series helpful - but it isimportant to make sure that the "code"for each item is clearly visible. The program DirctC1 is an example of adirect choice menu in mode 7, showingone style which I find useful. Thewords "Main Menu" at the top of thismenu are unnecessary, since there isonly one menu in this program, but theydo illustrate the principle of titlingmenus, which is important if there ismore than one in a program. Having displayed the menu options,it is important to make sure that thereis a clear prompt somewhere at eitherthe top or (more usually) the bottom ofthe menu asking the user for his or herchoice. If space permits, it is often agood idea to mention whether or notRETURN has to be pressed after thechoice has been entered. For most menus, a REPEAT-UNTIL loopwith a GET or GET$ command inside itwill usually suffice - this avoids theneed to press RETURN. This is themethod used in DirctC1. Examining the program will show thatthe method is very simple. Notice the*FX21 at line 440 - this flushes thekeyboard buffer to avoid the risk ofaccidental menu selection. The CHR$(GETAND &DF) in the next line is just thereto make sure that an upper casecharacter is returned whether or notCAPS LOCK is on. If it is important to ensure thataccidental choices are not made, then a"confirmation key" can be used whichmust be pressed after a choice has beenmade. The 8BS menu uses this approach -although in this case it is alsonecessary because the choice containsmore than one character. This type of system can be implentedusing the INPUT statement (orpreferably a programmed version of thiswhich avoids some of the problems withINPUT - such as the ability to entercontrol codes and the inability tocontrol length). Alternatively, the method illustratedin DirctC2 can be used. The menu routine is slightly morecomplex here. Up to line 430,everything should be obvious - do note,however, that all the menu options areindented by 1 space (TAB(1,y)) to allowfor the insertion of the flash controlcode. Line 430 itself stores the X and Yposition of the space after the "Yourchoice?" prompt - this is to enable thechoice to be printed at the appropriatepoint even after moving the cursor else-where. Line 450 sets the choice to 1 - this isdone because when a new choice is made,the old one must be made to stopflashing. The first time around theloop, no old choice will have beenmade, so this line "pretends" thatchoice 1 has been made to allow it tobe blanked correctly. Line 460 sets a flag (choice`made%) toshow that this is not a real choice -otherwise, RETURN could be pressedbefore a selection has been made fromthe menu. This is checked in the UNTIl statementin line 510 - a RETURN will only beaccepted if a choice has been made. Line 520 is the real heart of the menuroutine. If RETURN has not beenpressed, the choice`made% flag is setto TRUE, the choice is displayed nextto the "Your choice?" prompt, the oldchoice is prevented from flashing byprinting over the "flash code" with the"stop flashing" code and choice% is setto the new choice. Finally, a flashcode is printed next to the new choice.Note that a default choice can beprovided (if required) by making slightmodifications to the code - asdemonstrated in DirctC3. The changesinvolve setting choice% to the defaultchoice, removing the choice`made% flagand modifying the initial displayappropriately. Although this menu routine is not toolong, if you are using several menus,it might be worthwhile removing theactual input routine to a separatefunction - DirctC4 is a version ofDirctC3 using this method. The selection code has been transferredto a separate function (FNmenu`select(default%,choice`x%,choice`y%,options%,offset%) which can be used by any menuroutine. The parameters are: default% - this is the number of theoption which will be selected asdefault. If no default option isrequired, set this to -1. choice`x%, choice`y% - these are the Xand Y coordinates respectively at whichthe letter corresponding to the choiceshould be displayed options% - this is the number ofoptions in the menu offset% - this is the Y coordinate ofthe first line in the menu As always, you are free to use any ofthe routines provided with this articlein your own programs, provided you donot make any profit from them - amention in the documentation would alsobe appreciated, if possible! In the next article, I intend to coverstep selection menus.