Buttons Tutorial

From BR Wiki
Revision as of 01:25, 16 July 2013 by Laura (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Now that the user has input all the data into your CHAPTER1 program, instead of hitting the escape key, wouldn't it be great to have an exit button? Or a button to complete other actions like print a mailing label or prepare an invoice? Since version 4.15, BR can create buttons on the screen.

Take a look at this example:

00500    print fields "23,30,CC 8,,B99" : "Done"

Buttons are created using PRINT FIELDS, with the starting row and column, attributes (Characters and Centered in this case), button size (in columns), the B (for button!) and the FKEY value, which is set to 99 in this case. After the colon is the caption. If you run this example, it will print the button beautifully but do nothing.


That's because buttons depend on the program waiting for the user to click it, which sets the Fkey value, and so triggers the desired action. Therefore, the program must be waiting for something else to happened as it waits for that Fkey to be set (by clicking it). It could wait for a checkbox or radio button selection, input information, or even just a dummy input. For this reason, buttons pair well with input forms.

Here's an example:

00490    dim box$(3)
00500    print fields "23,30,CC 8,,B99" : "Done"
00510    data "Item 1","Item 2","Item 3"
00520    read mat Box$
00530    do
00540       rinput fields "22,14,CHECK 8,,10;23,14,CHECK 8,,11;24,14,CHECK 8,,12": Box$(1),Box$(2),Box$(3)
00550       print fields "24,1,N 2": Fkey
00560    loop While Fkey~=99

Line 500 creates the button on the screen with print fields “row,col, attributes length, , B99”, where the B stands for button and the 99 sets the FKEY value. After the colon, the “Done” will be the label on the button. This example lets the user choose from several checkboxes, and then click the button, which ends the LOOP and in this case the program. In other programs, the FKEY could be set to run other activities as well.

Exercise 1.3

A. Add an exit button to the sample program that we've been working on in this chapter. See the solutions if necessary.

B. For use in the next sections, also add input fields for customer name and address, then write all the information into a file called ORDERS.INT. Run the program several times so that you have quite a few entries in the file to work with (this should all be review from the first tutorial). Once again see the solutions page if you need help.

Next: Lists
Back: Table of Contents