Fast Track 3

From BR Wiki
Jump to navigation Jump to search

Handling User Interaction

Users can access and add information through a variety of ways:

Input fields – so far we've been working in the command console, but your program users will be handling information through the GUI console. For this, start with print fields and input fields, which use character based positioning to print and receive data from the screen.

Print fields "8,4,c 14": "Customer Name:"
Print fields "12,4,c 10":"Email:"
Input fields "8,20,c 50":name$
Input fields "12,20,c 50":email$

Then you can write it to a data file using OPEN, WRITE, and CLOSE, as described above.

Next add a save and edit button.

00340    PRINT FIELDS "23,30,CC 8,,b99" : "Save"

The syntax allows you to position the button, and set an FKEY, 99 in this case, to determine what the button will do, in this case Write the record to a data file. Buttons need something to wait on, one easy way to do this is to have a loop running:

01100    print fields "23,30,CC 8,,b99" : "Save"
01200    do
01300      input fields "24,1,c 1": nomatter$
01400    loop While Fkey~=99
01500     if fkey=99 then
01600     rewrite #emailfile, USING emailform:  name$, email$
01700     else goto end

Clicking the button will end the loop and do that action you've programmed it to.

For other widgets see: Grid and List, Radio Buttons, and Checkboxes tutorials.

When displaying data on the screen, the internal functions PIC and FMT use digit identifiers and insertion characters to make the appearance more user-friendly. For example, adding commas and zero suppression into financial expressions:

00010 PRINT USING 20: 1000,1000
00020 FORM PIC($$$,$$$),X 2,PIC($ZZ,ZZZ)

Would return:

$1,000 $ 1,000

FMT is more useful for string manipulation, as it can be used to set case and add punctuation.

ERROR HANDLING

One way to handle errors is using error conditions at the end of your statement lines.

Error conditions are keywords which are used to trap errors that occur during program execution. Each error condition keyword identifies one or more types of errors that typically occur during program execution.

ON ERROR is another way to handle errors (a more catch-all method).

RETRY is a command that will restart the program again at the line where the error occurred, while CONTINUE will start at the line just after.

INTERNAL FUNCTIONS

BR has a lot of internal functions built in. For a complete list and descriptions, check the wiki. These functions can be used to alter and handle data bits for you, manipulate forms and other tricks.

NEXT:Debugging