Functions


CFORM$(A$) Release 3.50

The CFORM$ function clears the way for programs to use a variable for I/O format without the performance drawbacks that are typically associated with this usage.

In the past, use of a variable for I/O formatting, as in the statement

READ #1 USING A$: {variables}

has been discouraged because the A$ string must be compiled on each execution of the READ statement. (A$ contains the format information that would otherwise be specified in a FORM statement.)

The CFORM$ function allows programs to "compile" format variables prior to their use. In the following sample code fragment, the contents of A$ are compiled by CFORM$ and reassigned to A$. This is done prior to the execution of a loop where A$ is used as the format variable.

1000 A$=CFORM$(A$)
1010 FOR X=1 TO 100
1020 READ #1,USING A$:variables
1030 NEXT X

Please note that variables which are compiled by CFORM$ will be in an unreadable, machine-dependant internal format. Because of this, programs should never compile a format with CFORM$ and save it to a file for use by other programs. The output of CFORM$ can vary with each machine and with each release of Business Rules!.

CMDKEY Release 3.30

The CMDKEY function now accepts a value. This is useful for KSTAT$ processing and for setting expected CMDKEY inputs without operator intervention. In the following sample syntax, CMDKEY is assigned the value of x:

LET CMDKEY(x)

CMDKEY now returns values of 90 and 91 for the PgUp and PgDn keys during program input. See "PgUp and PgDn" in the Keys section for more information.

CURFLD([firstfield][,attribute$][,FKEY])

Release 3.50

CURFLD has been extended to allow an additional numeric parameter, an FKEY value, that causes FIELDS and SELECT statements to execute the specified keystroke before requesting operator input. CURFLD ignores FKEY values of 100 or less and of 114 or greater. The following code uses CURFLD and FKEY to trap the operator's field exit keystroke and execute it after verifying the data just entered. Note that the AE control attributes are used to interrupt execution of the INPUT FIELDS statement upon field exit.

00010 PRINT NEWPAGE
00020 INPUT FIELDS "10,10,C 10,AEU:R;11,10,C10,U": X$,Y$ HELP 41
00030 IF CURFLD=1 THEN PRINT FIELDS "10,22,C": X$
00040 IF FKEY>100 THEN LET CURFLD(CURFLD,FKEY) : GOTO 20
00041 PRINT FKEY
00050 STOP

As soon as the operator attempts to exit the first input field, line 30 verifies the entered data by redisplaying it to the right of the field. The CURFLD function in line 40 is then used to reenact the operator's field exit operation: the field just verified is set to the current field, and the operator's attempted exit keystroke (the value of FKEY) is executed. Operator input is then allowed for the next field.

Note: If the up arrow was the last key used, the cursor will return to the previous field. If the tab key was used, the cursor will position tothe next field with a T (tab stop) attribute.

Note that the CURFLD function in line 40 is executed only if the value of FKEY is greater than 100. Values of 100 or less are ignored, as are interpreted as an attempt to enter the entire screen.

Release 3.50

CURFLD will now process field control attributes such as AEP and #. These control attributes will be ADDED to the control attributes that are specified for a field. Also, the attributes that are specified with CURFLD will OVERRIDE (be used instead of) a floating attribute specified with ATTR. The CURFLD attributes will remain in effect only during the next execution of an INPUT FIELDS or INPUT SELECT statement. Line 20 in the following example uses the X control attribute (see the "X control attribute" discussion in the Wbconfig.sys Specifications section for more information).

10 INPUT FIELDS "10,10,V 10,U;11,10,V 10,U;12,10,V 10,U",attr "HU":X$,Y$,Z$
20 IF X$="" THEN LET CURFLD(1,"RX") : GOTO 10
30 !.. other editing
40 IF FKEY>100 THEN LET CURFLD(CURFLD,FKEY) : GOTO 10
50 !.. output

If the first field displayed by the above code is left blank, the CURFLD function in line 20 will reposition the cursor to that field and display it in reverse video. The CURFLD function's X attribute will additionally cause an auto-enter to occur when the operator attempts to re-exit the field. If the field passes the test on line 20, and the enter key or a function key was not pressed, the field attribute will resume as an underline and the cursor will be positioned at the next field the operator was trying to move to.

ADS expects that line 40 will become a standard line of code in all programs that use input fields and validate data.

DATE([days][,[*]format$]) Release 3.61

The "C" - century format specification is now fully supported. If the century is not specified, it is simply not printed.

Examples:

PRINT DATE$("M/D/CY")
output: 07/10/1992

PRINT DATE$(DAYS(07101992,"MDCY"),"M/D/Y")
output: 07/10/92

PRINT DATE$(DAYS(07102092,"MDCY"),"M/D/Y")
output: 07/10/92

DAYS(date[,format$]) Release 3.61

The "C" - century format specification is fully supported. BASEYEAR is used to determine the century for a date if the format specification used does not specify a century. See "BASEYEAR" in the Wbconfig.sys Specifications section for complete information.

EXISTS(filename) Release 3.70

The EXISTS function now returns a value of 1 for directories, and a number greater than 1 for files.

FKEY Release 3.50

The FKEY function is similar to CMDKEY, but returns more information about how a field is exited. Note that FKEY is now a reserved word and this change will affect current programs. We will be providing a utility to change occurrences of FKEY in existing applications to something else. The following table shows a comparison of the values that are returned by FKEY and CMDKEY when a particular key is pressed to terminate field input.

Key Pressed   FKEY Value    CMDKEY Value 
Ctrl-C 0 0
Enter 0 0
Function Keys 1-49 1-49 1-49
Page Up 90 90
Page Down 91 91
Help (Ctrl-Y) 100 0
Timeout Error 101 0
Up Arrow 102 0
Left Arrow from first position in a
field (move to end of previous
field)
103 0
Down or Right Arrow 104 0
Up Field (Ctrl-R) 105 0
Down Field (Ctrl-V) 106 0
Next Field due to character
overflow
107 0
Tab (when T used in fields
attribute)
110 0
Shift-Tab 111 0
Home 112 0
End 113 0

FKEY(X) sets the value of FKEY to X. It also sets the value of CMDKEY. However, if X is greater than 91 then CMDKEY is set to zero. Likewise, the function CMDKEY(X) sets both CMDKEY and FKEY to the value of X.

KREC(filenbr) Release 3.61

When processing a linked list file, KREC is updated with the location of an anchor record only under the following conditions:

RESTORE REC={non-anchor}sets KREC to zero. KREC remains otherwise unaffected during READ and WRITE statement processing.

LINES(filenbr) Release 3.53

This returns the number of lines printed since the last new page. "Filenbr" should represent a display file. This function is identical to KREC as used with display files, just more appropriately named.

LINESPP(filenbr) Release 3.53

This feature supports programs that are sensitive to various page lengths. It returns the current lines per page as set by a wbconfig.sys PRINTER spec's LPP parameter, or 66 by default. If an LPP value is specified in a wbconfig.sys PRINTER spec, LINESPP will return that value after that PRINTER substitution has been used by a PRINT statement.

In the following example, the unbracketed "LPP 48" parameter sets the value of LINESPP to 48. In the code fragment that follows it, line 30 executes a PRINT statement that utilizes the PRINTER substitution. At that point, the value of LINESPP is changed to 48.

PRINTER LPP 48 [SET48],"\Ep48"
10 OPEN #255:"NAME=PRN:/10",DISPLAY,OUTPUT
20 PRINT LINESPP(255)
30 PRINT #255:"[SET48]"
40 PRINT LINESPP(255)

Program output would be:
66
48

This feature was designed to support the transparent use of both dot matrix and laser printers on the same system. When printing reports that require more than 80 columns or more than 132 columns, a number of options exist to print that same report in landscape mode (sideways), which changes the number of printable lines per page.

The following is a table showing the common columns per page and the mode required for dot matrix and laser printers:

----- Dot Matrix ----- Laser/Compress Laser
COLUMNS 8.5"x11" 14"x11" (use 17cpi) (avoid 17 cpi)
CPI LPP CPI LPP CPI LPP CPI LPP
[COLS=80] 10 66 10 66 10 66 10 66
[COLS=96] 12 66 10 66 12 66 12 66
[COLS=100] 17 66 10 66 17 66 10 51
[COLS=120] 17 66 10 66 17 66 12 51
[COLS=132] 17 66 10 66 17 66 17 66
[COLS=158] ** ** 12 66 17 51 17 51
[COLS=170] ** ** 17 66 17 51 17 51
[COLS=224] ** ** 17 66 ** ** ** **

Also, since many laser printers have scalable fonts or font cartridges, a larger point size may be chosen for [COLS=132]. Without any extra program code, simply select the number of columns needed for the report from the above list:

PRINT #255,USING "FORM C,SKIP 0":"[COLS=132]"

and use LINESPP to get the number of lines per page in this format:

MAXLINES = LINESPP(255)

LOG(x) Release 3.30

Now accepts only positive, non-zero values for its parameter.

LPAD$(A$,X[,"char"])

RPAD$(A$,X[,"char"]) Release 3.53

An optional third parameter ("char") has been added to LPAD$ and RPAD$ to specify the character to be used for the padding (instead of blanks, which are still the default). The "char" parameter is limited to one character in length (error 410 will result if it is longer). Nulls and CHR$(0) are allowed.

LTRM$(A$[,"char"])

RTRM$(A$[,"char"]) Release 3.53

An optional second parameter ("char") has been added to LTRM$ and RTRM$ to specify the character to strip (instead of blanks, which are still the default). The "char" parameter is limited to one character in length (error 0410 will result if it is longer). Nulls and CHR$(0) are allowed. The following statement would return the value 12:

PRINT RTRM$("1200","0")

NEWPAGE Release 3.30

The NEWPAGE function no longer outputs a carriage return to display files when used in the following form:

PRINT #255: NEWPAGE

Previously, NEWPAGE would output both the newpage character (FF-chr$(12)) and a carriage return (CR - chr$(13)) character. The carriage return has been removed because some printers were using it to move the paper up an extra line, or they weren't recognizing the escape sequences that followed it. Be aware that this may affect printed or spooled reports.

PROGRAM$ Release 3.53

The PROGRAM$ function can now be used to return the full name and path of the currently loaded program. It can be very useful in common error routines.

SLEEP (seconds) Release 3.50

The SLEEP function causes the processor to wait the specified number of seconds before continuing execution. It does not tie up the processor while waiting, which is especially important for multi-user systems.

TRIM$(A$[,"char"]) Release 3.53

The TRIM$ function can now be used to delete both leading and trailing blanks from the string A$. TRIM$(A$) returns the same value as RTRM$(LTRM$(A$)). The optional "char" parameter can be used to specify the character (instead of blanks) to strip; this parameter is limited to one character in length. Nulls and CHR$(0) are allowed.

VARIABLE$ Release 3.53

VARIABLE$ returns the name of the variable that failed in the last I/O statement. Besides being invaluable for debugging, VARIABLE$ can be used as a topic to call HELP$. Note: VARIABLE$ will not be set if the error results from the field specification (error numbers 850 through 890). Also, if the field is a calculation such as A+B, VARIABLE$ will not be set.

VERSION(filenbr[,newversion]) Release 3.53

The VERSION function returns or optionally resets a file version number for the opened file number specified. This feature allows you to verify that data files have been updated to match the current program release.

The filenbr parameter represents the number of an open internal file. If the file is not an internal file or the file is a key file opened as an internal file, a 0721 (I/O conflicts with OPEN) error will result.

The new version parameter can be used to reset the version number of the specified file. When newversion is specified, the file must be opened for OUTIN or a 0721 error will result. The newversion number is not written to the disk until the file is closed. The newversion specified can be any number from 0 to 32000.

The VERSION function is designed to be used in conjunction with the VERSION= parameter for OPEN internal statements. VERSION= should be used to set the version number on newly created data files and to trap situations where the data files are not current for the program being run. This would stop the program from processing faulty data before any data could be processed. It is up to the programmer to maintain the version numbers in the programs.

Not every program should check for version numbers, as every time the version changed, all the VERSION= parameters would need to be changed. Posting and file maintenance programs would be the most likely candidates to use VERSION=.

The VERSION function is intended to be used in a "data file update program." The update program should contain code to convert each successive version. For example:

OPEN #1:"NAME=CUSTOMER.DAT",INTERNAL,OUTIN
IF VERSION(1)=1 THEN ! record length increased for C 5
CLOSE #1:
EXECUTE "COPY CUSTOMER.DAT WORK[WSID] -160 -N"
EXECUTE "FREE CUSTOMER.DAT -N"
EXECUTE "RENAME WORK[WSID] CUSTOMER.DAT -N"
OPEN #1:"NAME=CUSTOMER.DAT",INTERNAL,OUTIN
LET VERSION(1,2) ! update to version 2
CUSTOMER=1 ! Changed flag
END IF
IF VERSION(1)=2 THEN ! change field length
RESTORE #1:
FORM1: POS 80,C 10,C 3 ! C 3 was C 5
FORM2: POS 80,C 12,C 3
LOOP1: READ #1,USING FORM1: A$,B$ EOF ENDLOOP1
REWRITE #1,USING FORM 2: A$,B$
GOTO LOOP1
ENDLOOP1: VERSION(1,3) ! update complete to version 3
CUSTOMER=1
END IF
IF CUSTOMER THEN !:
     PRINT "CUSTOMER.DAT UPDATED TO CURRENT VERSION."

The above code would convert a data file from whatever version the data file was to the most current. Whenever a file layout is changed, you would simply add the conversion routine to the end of this program.