Internal Functions Tutorial

From Br Wiki
Jump to: navigation, search

Internal functions are built into Business Rules to return either a numeric or string value after performing an action on the variable. Some functions affect blank spaces in string values or perform arithmetic to a numeric value. Internal functions can also perform on arrays.

A complete list of internal functions is available on the BR wiki at Internal Functions.

Several commonly used internal functions include:

KSTAT$(X)

1. KSTAT$(X) – KSTAT$ can do three things. Alone, it will will return any keystrokes entered that were not already processed. With a numeric value in X, it is used to provide a pause and wait for the user to hit X number of keys. This has a variety of applications, including “Push any key to continue” instructions within a program. KSTAT$ also provides a timeout option, where the program will wait Y number of seconds for the user to push something. If the user doesn't hit any keys, then the program will continue and then can be made to do something else.

UDIM

2. UDIM(arrayname,X) – returns the number of rows in an array. The optional parameter X will return the number of columns in that dimension. For example if X=2, UDIM will return the number of columns. If X=3 it will return the number of planes in that dimension and so on. When only the array name is used, UDIM returns the size of the first dimension (number of rows).

UDIM can be used to READ a file that has an unknown or growing number of records, as seen in the RADIOBUTTONS example program:

00390     For I=1 to UDIM(box$)
00400         if box$(I)(1:1)="^" then ordered(I)=1 else ordered(I)=0
00410     next I

UPRC$ and LWRC$

3. UPRC$(X), LWRC$(X) – provides the uppercase or lowercase version of the string value of X. This is useful for when the user enters information that needs to be in a case-insensitive format.

TIME$

4. TIME$ - returns the system time in the format hh:mm:ss. This can be used in files to provide a unique key for each record. Enter TIME$ in ready mode and it should return the exact time you pressed Enter.

REC and LREC

5. REC(filename) – returns the record number of the last record processed in the file. Closely related, LREC(filename) will return the total number of records processed.

Chapter 3 Exercises

1. Create a menu-like list that will return the selected value using kstat$.

2. Change the program from Chapter 1.4 so that all the last names in the ORDERS.int file will be printed out in all-caps in the LIST.

3. Add an item to the program writing ORDERS.int that records the time which the record was entered.

4. Add a line to the same LIST program as number 1 above in order to print the total number of entries in the list.

See the Solutions for help.


Next: Libraries
Back: Table of Contents