# LISTBOX Command

The LISTBOX command allows you to put up a series of choices and capture the element number of the one chosen by the user. You can use this number to GOTO or GOSUB through routines associated with each individual choice.

Here is something useful you can do with LISTBOX and printing.

After a new invoice record is placed on file and the user presses ESC ESC to store the record, the question is asked, "Do you want to print an invoice?" If the answer to this question is yes, the form is printed. In the past, all invoices printed on the same main printer in an outer office. This is inconvenient. If each user has access to his own printer, and this personal printer is named after him, personalized printing can occur very easily. You may find that an adaptation of the following will work for you too.

LISTBOX puts a window up on your screen. The size and location of the window are preset by default, but can be altered to suit your needs. The contents of this box are really a menu of choices, with the standard filePro highlighted bar cursor and selection mechanism. (You can press the first letter of any of the choices and the cursor jumps right to it.) The choices are elements of an array, which you fill on the processing table. They can be variable and change each time you call up the LISTBOX. In this example, they are variable based on the login name of whatever user is operating the program. (In this model, provisions are made for only four users and "hard-coded" into the table. The implementation at Guru Headquarters is actually more elaborate, and dynamically allows for new users/printers, but this example is meant only to illustrate a good use for LISTBOX. This function is more clearly presented in this manner, and not obscured by the other code.)

Besides the ability to print an invoice (or any form, of course) on any of three printers, the added sophistication of defaulting to the users own printer is very friendly. When Robin is logged in at her terminal, she sees her printer as the first (default) choice and can just press RETURN under normal printing conditions. If, for some reason, she is logged in at Karens terminal and wants to print, as always, at her own printer, she still just presses RETURN as usual. She would need to make a conscious decision to move the cursor bar or pick a different selection by letter if she doesnt want her default. (You would be surprised how many times it Is necessary to print on anothers printer... out of paper, letterhead isnt loaded, printer is broken, someone forgot to buy new toner, printer isnt warmed up yet... etc., etc. If you cant think of any other reasons, call Robin or Karen; theyll give you a bunch more. -ed)

Processing_tables: input

If:

Then: your input processing goes here

If: Build an array that holds 3 elements (printer names)

Then: dim printers[3](10)

If: @id="karen" fill array based on person.

Then: printers["1"]="karen";printers["2"]="robin";printers["3"]="john"

If: @id="robin" making sure the running user is the first element

Then: printers["1"]=-"robin";printers["2"]="karen";printers["3"]="john"

If: @id="root" or @id="john"

Then: printers["1"]="john";printers["2"]="karen";printers["3"]="robin"

If:

Then: gosub doprint

If:

Then: end

doprint If:

Then: cls("21","4")

If:

Then: input q(1,yesno) "Do you want to print this invoice? (y/n) "

If: q ne "Y"

Then: goto label

If:

Then: show "\r What printer should be used? \r"

If:

Then: pr(1)=listbox(printers,"","","20","56")

If:

Then: printer type "dumb"

If:

Then: printer "lp -s d{printers[pr]" ; form "invoice" ; printer reset

If:

Then: cls("21","4")

label If:

Then: input q "Do you want to print a label? (y/n)"

If: q ne "Y"

Then: return

If:

Then: printer type "dmp2100";printer "lp -dlabel s"

If:

Then: form label;printer reset;return