Internal Functions: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
(edit)
(Redirected page to Category:Internal Functions)
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
BR has more than 97 built-in '''internal functions''' that return either [[numeric]] or [[string]] values. By using internal  functions for tasks such as [[searching]] or [[summing an array]], both programmers and programs can be more efficient in getting their jobs done. Numeric functions may be used anywhere that a numeric expression is valid.  Likewise, string functions may be used anywhere that a string expression is valid.
#Redirect:[[:Category:Internal Functions]]
 
This section presents these internal functions in alphabetical order. Their purpose is described, comments and examples are provided and related functions are mentioned.
 
===Syntax Conventions===
 
Numeric values are symbolized by the [[Variable|variables]] X and Y.  String variables are symbolized by A$, B$, and C$. File reference numbers are symbolized by N, where N is the number associated with an opened file.  Square brackets around a parameter indicate the parameter is optional. In all cases, the parameters or arguments which are passed remain unchanged.
 
Most Business Rules! internal functions are presented in syntax sentences rather than in syntax diagrams. Punctuation must be specified as indicated in these sentences. Numeric values are symbolized by X and Y whereas strings are symbolized by A$, B$ and C$.
 
File reference numbers are symbolized by N, where N is the number associated with an opened file.
 
<noinclude>
===Abs===
 
{{:Abs}}
 
===AIdx===
 
{{:AIdx}}
 
===Atn===
 
{{:Atn}}
 
===Bell===
 
{{:Bell}}
 
===Ceil===
 
{{:Ceil}}
 
===CForm$===
 
{{:CForm$}}
 
===Chr$===
 
{{:Chr$}}
 
===CmdKey===
 
{{:CmdKey}}
 
===Cnt===
 
{{:Cnt}}
 
===Cnvrt$===
 
{{:Cnvrt$}}
 
===Code===
 
{{:Code}}
 
===CoS===
 
{{:CoS}}
 
===CurCol===
 
{{:CurCol}}
 
===CurFld===
 
{{:CurFld}}
 
===CurRow===
 
{{:CurRow}}
 
===Date===
 
{{:Date (Internal Function)}}
 
===Date$===
 
{{:Date$}}
 
===Days===
 
{{:Days}}
 
===DIdx===
 
{{:DIdx}}
 
===Env$===
{{:Env$}}
 
===Err===
 
{{:Err}}
 
===Exists===
 
{{:Exists}}
 
===Exp===
 
{{:Exp}}
 
===File===
{{:File}}
 
===File$===
 
{{:File$}}
 
===FileNum===
 
{{:FileNum}}
 
===FKey===
 
{{:FKey}}
 
===FP===
{{:FP}}
 
===FreeSp===
 
{{:FreeSp}}
 
===HELP$===
 
Help$("[*]topic[,filename]"[,mark])
 
The '''Help$''' [[internal function]] displays a help screen. "Topic" is the name of the help topic to be displayed. The "filename" is optional. When a file name is not specified, the system uses the file named in the [[HLPDFLT]] specification in the [[BRConfig.sys]] file or with the [[CONFIG]] command; if HELPDFLT has not been coded and HELP$ is used without a file name, an error will occur.
 
If the topic name starts with an asterisk (*), the screen is not saved or restored by the help call. The asterisk has no affect on the search for the topic within the text.
 
"Mark" is an optional number that indicates which part of the topic text to display first. It correlates to a carat (^) character in the text. If mark is specified as 3, the text located after the third carat in the topic text will be displayed on the screen first, although the operator still will be able to review all text associated with the topic.
 
====Comments and Examples====
110 LET X$ = HELP$("HOURS.ENTRY",CURFLD)
 
====Related Functions:====
*[[CURFLD]]
 
====Technical Considerations====
:1.) See [[Help Facility]] for information about preparing and using on-line help screens.
 
===Hex$===
 
{{:Hex$}}
 
===INF===
 
Inf
 
The '''Inf''' [[internal function]] returns the [[largest possible number]] in [[Business Rules!]] on the current system. For current [[DOS]], [[Network]], [[Unix]] and [[Linux]] systems, Inf is [[1.000000E+307]]. To find the [[smallest number]], use PRINT 1/INF.
 
===INT===
 
Int(X)
 
The '''Int''' [[internal function]] returns the largest integer less than or equal to X.
 
====Comments and Examples====
INT(+5.1) is 5, but INT(-5.1) is -6.
 
====Related Functions:====
*[[Abs]]
*[[CEIL]]
*[[FP]]
*[[IP]]
*[[Round]]
 
====Technical Considerations====
:1.) When set to 0, the RD specification in BRConfig.sys can affect the INT function.
 
===IP===
 
{{:IP}}
 
 
===KLn===
 
{{:KLn}}
 
===KPs===
 
{{:KPs}}
 
 
===KRec===
 
{{:KRec}}
 
===KStat$===
 
{{:KStat$}}
 
===Len===
 
{{:Len}}
 
===Line===
 
{{:Line}}
 
===LINES===
 
Lines(filenbr)
 
The '''Lines''' [[internal function]] 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===
 
LineSPP(filenbr)
 
The '''LineSPP''' [[internal function]] supports programs that are sensitive to various page lengths. It returns the current lines per page as set by a BRConfig.sys PRINTER spec's LPP parameter or 66 by default. If an LPP value is specified in a BRConfig.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, 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<br>
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:
 
[[Image:Help0172.jpg]]
 
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===
 
Log(X)
 
The '''Log''' [[internal function]] now accepts only positive, non-zero values for its parameter. Calculates the natural logarithm of X.
 
====Related Functions:====
*[[ATN]]
*[[COS]]
*[[EXP]]
*[[PI]]
*[[SIN]]
*[[TAN]]
 
===LOGIN_NAME$===
 
Login_Name$
 
The '''Login_Name$''' [[internal function]] contains the [[operating system]] [[user login name]]. This can also be set with LOGIN_NAME$("newname").
 
The priority of the LOGIN_NAME variable setting is:
 
:1)  BR startup parameter (@name)
:2)  Windows 95/NT or Unix login name
:3)  BRCONFIG.SYS "LOGIN_NAME name" statement
 
These alternatives support the assignment of login name in all models.  This can significantly simplify the tailoring of [[BRCONFIG.SYS]] files through use of the @name statement prefix.  Instead of having to place a separate BRCONFIG.SYS file on each client system, the client's could specify the login name of the user, and a common BRCONFIG.SYS file could contain the custom statements for all users, beginning the custom statements with @name for each login name.
 
e.g. BR  @myname  run menu
 
BRCONFIG.SYS includes:
 
@myname WSID 25
@myname PRINTER OKIDATA
 
===LPad$===
 
{{:LPad$}}
 
===LRec===
 
{{:LRec}}
 
===LTRM$===
 
{{:LTrm$}}
 
===LWRC$===
 
LwrC$(A$)
 
The '''LwrC$''' [[internal function]] converts any uppercase letters in the string A$ to lowercase letters.
 
====Comments and Examples====
10 LET A$ = "E. E. Cummings"
20 PRINT LWRC$(A$)
 
Line 20 will print:
e. e. cummings
 
====Related Functions:====
See the UPRC$ function for conversion from lowercase to uppercase.
 
====Technical Considerations====
:1.) Another method for conversion to lowercase is the CL, VL and GL format specifications, which are effective only with INPUT FIELDS and RINPUT FIELDS. This method converts keystrokes, as they are being entered, into lowercase only. See also the CU, VU and GU format specifications for more information about converting incoming keystrokes to uppercase.
 
===MAX===
 
MAX(X1,X2...)
 
The '''Max''' [[internal function]] returns the largest numeric value in the set of numbers inside parentheses (X1, X2 and
so on).
 
====Comments and Examples====
10 LET A = 8
20 LET B = 10
30 LET C = 5
40 PRINT MAX(A,B,C)
 
The above program will print the number 10.
 
====Related Functions:====
[[MAX$]] is a similar function for strings. [[MIN]] and [[MIN$]] return the smallest values.
 
====Technical Considerations====
:1.) The number of items that can be listed inside the parentheses is limited only by the maximum line length of 800 characters in source code or 255 characters in compiled code.
 
===MAX$===
 
MAX$(A1$,A2$,..)
 
The '''Max$''' [[internal function]] returns the largest string value in the set of strings inside parentheses (A1$, A2$ and so on). When comparing strings, the largest value is the one with the highest ASCII value. If only letters of the alphabet are being compared, MAX$ will return the string that is last in alphabetical order.
 
====Comments and Examples====
10 LET A$ = "red"
20 LET B$ = "green"
30 LET C$ = "blue"
40 PRINT MAX$(A$,B$,C$)
 
The above program will print the string "red" (without the quotation marks).
 
====Related Functions:====
[[MAX]] is a similar function for numbers. Similarly, [[MIN$]] and [[MIN]] return the smallest values.
 
====Technical Considerations====
:1.) The number of items that can be listed inside the parenthesis is limited only by the maximum line length of 800 characters in source code or 255 characters in compiled code.
:2.) The COLLATE option in effect when the program was last saved or in the OPTION statement can alter the string comparisons within the MAX$ function.
 
===MIN===
 
MIN(X1,X2...)
 
The '''Min''' [[internal function]] returns the smallest numeric value in the set of numbers inside parentheses (X1, X2 and so on).
 
====Comments and Examples====
10 LET A = 8
20 LET B = 10
30 LET C = 5
40 PRINT MIN(A,B,C)
 
The above program will print the number 5.
 
====Related Functions:====
[[MIN$]] is a similar function for strings. [[MAX]] and [[MAX$]] return the largest values.
 
====Technical Considerations====
:1.) The number of items that can be listed inside the parenthesis is limited only by the maximum line length of 800 characters in source code or 255 characters in compiled code.
 
===MIN$===
 
MIN$(A1$,A2$,...)
 
The '''Min$''' [[internal function]] returns the smallest string value in the set of strings inside parentheses (A1$, A2$ and so on). When comparing strings, the smallest value is the one with the lowest ASCII value. If only letters of the alphabet are being compared, MIN$ will return the string that is first in alphabetical order.
 
====Comments and Examples====
10 LET A$ = "red"
20 LET B$ = "green"
30 LET C$ = "blue"
40 PRINT MIN$(A$,B$,C$)
 
The above program will print the string "blue" (without the quotation marks).
 
====Related Functions:====
[[MIN]] is a similar function for numbers. Similarly, [[MAX$]] and [[MAX]] return the largest values.
 
====Technical Considerations====
:1.) The number of items that can be listed inside the parentheses is limited only by the maximum line length of 800 characters in source code or 255 characters in compiled code.
:2.) The COLLATE option in effect when the program was last saved or in the OPTION statement can alter the string comparisons within the MAX$ function.
 
===MOD===
 
{{:Mod}}
 
===Msg===
 
{{:Msg}}
 
===MSG$===
 
Msg$(A$)
 
The '''Msg$''' [[internal function]] displays A$ in the message area of the status line.
 
====Comments and Examples====
The following example displays the message "Now creating backup file" (without the quotation marks) in columns 9 to 37 (the message area) of the status line.
 
MSG$("Now creating backup file")
 
The next example sends a null string to the status line:
 
MSG$("")
 
====See also====
[[STATUSLINE]] in [[BRConfig.sys]] and the status line information in [[Getting Started]].
 
===MsgBox===
 
{{:MsgBox}}
 
===NewPage===
 
{{:NewPage}}
 
===Ord===
 
{{:Ord}}
 
===OS_FileName$===
 
{{:OS_FileName$}}
 
===Pi===
 
{{:Pi}}
 
===PIC$===
 
Pic$(A$)
 
The '''Pic$''' [[internal function]] by itself returns the current currency symbol. Used with A$, it defines a new currency symbol to be A$.
 
====Comments and Examples====
00010 PRINT "The currency symbol is ";PIC$
00020 PRINT USING 30: 12.34
00030 FORM PIC($$$$.##)
00040 PRINT "The new currency symbol is ";PIC$("#")
00050 PRINT USING 30: 12.34
 
The output from running the above program (assuming the default for PIC$ was not changed since starting Business Rules ) would be:
 
The currency symbol is $<br>
  $12.34
 
The new currency symbol is #<br>
  #12.34
 
====Related Functions:====
For other features especially useful in markets outside the United States, see the [[INVP]] parameter of the [[OPTION]] statement and the optional format string in the [[DATE$]] and [[DATE]] functions.
 
====Technical Considerations====
:1.) After using PIC$(A$) to change the currency symbol, it will stay changed until you exit Business Rules , or until another PIC$(A$) function is executed to change it again.
:2.) Some European customers may want to include this function in a procedure executed when starting Business Rules.
 
For example, the command that starts Business Rules could be:
 
BR "proc start"
 
and the procedure file START could include:
 
PIC$("#")
RUN MENU
 
:3.) On a multi-user system, changing the currency symbol at one workstation has no effect on other workstations.
:4.)  The string argument A$ must be exactly one character long when the syntax PIC$(A$) is used to change the currency symbol.
:5.) PIC((ZZZ,ZZZ.##)) now supports parentheses as digit identifiers (left side of the number only) and insertion characters, with the rule that parentheses will be output only if the number is negative. The left parenthesis that is closest to the number but not replaced with a digit will be output when the number is negative.
 
PRINT USING "FORM C 4,PIC((((ZZ,ZZZ.##))":"XXXx",-200
 
output:
 
XXXx  (  200.00)
 
PRINT USING "FORM C 4,PIC((((ZZ,ZZZ.##))":"XXXx",-200000
 
output:
 
XXXx (200,000.00)
 
===Pos===
 
{{:Pos}}
 
===ProcIn===
 
{{:ProcIn}}
 
===Program$===
 
{{:Program$}}
 
===Rec===
 
{{:Rec}}
 
===RLn===
 
{{:RLn}}
 
===RND===
 
Rnd([X])
 
The '''Rnd''' [[internal function]] returns a random number between 0 and 1. The optional numeric parameter X can be used to reset the random number generator so that the same random sequence can be generated again later.
 
====Comments and Examples====
The short program below will generate 10 random numbers between 0 and 1.
 
00010 FOR I=1 TO 10
00020  PRINT RND
00030 NEXT I
 
To rescale the random numbers to be between 1 and 100 and make them [[integers]], change line 20 to:
 
00020 PRINT INT(RND*100+1)
 
When the optional parameter is used with the RND function, it resets the random number generator so that the same random sequence can be generated again later. This feature should be added outside the loop so that the numbers produced inside the loop will be different. The following program will produce the same set of numbers each time it is run.
 
00010 LET X=RND(1)
00020 FOR I=1 TO 10
00030 PRINT RND
00040 NEXT I
 
====Related Functions:====
See also the [[RANDOMIZE]] [[statement]].
 
===ROUND===
 
Round(X,Y)
 
The '''Round''' [[internal function]] returns the value of X rounded to Y decimal places or to -Y whole number places.
 
====Comments and Examples====
The ROUND function can be used to eliminate decimal digits that are not going to be printed. Although Business Rules automatically rounds all formatted output to the specified number of decimal places, sometimes internally calculated numbers generate extra decimal places. For example, 3 divided by 8 equals .375 internally, but prints as .38 using N 10.2 format. Line 300 shows how to calculate 3/8 and round the answer to 2 decimal places at the same time. Even the unformatted print in line 400 will output .38 because the internal value of X has been set to this amount.
 
300 LET X = ROUND(3/8,2)
400 PRINT X
 
When the value of Y is negative, ROUND may also be used to round to the nearest multiple of 10, 100, 1000, etc. If the value of Z in the following example is 146,569, the ROUND function would round it to 146,600:
 
ROUND(Z,-2)
 
====Related Functions:====
ABS, CEIL, FP, INT, and IP
 
===RPad$===
 
{{:RPad$}}
 
===RPT$===
 
Rpt$(A$,X)
 
The '''Rpt$''' [[internal function]] returns A$, repeated X times.
 
====Comments and Examples====
Line 10 will print a row of stars (asterisks) on the printer that is 132 columns long.
 
00010 PRINT #255: RPT$("*",132)
 
===RTrm$===
 
{{:RTrm$}}
 
===Serial===
 
{{:Serial}}
 
===SetEnv===
 
{{:SetEnv}}
 
===SGN===
 
Sgn(X)
 
The '''Sgn''' [[internal function]] returns a value which identifies whether a numeric value is negative, positive or zero. The returned values are as follows:
 
-1 if X is negative<br>
0 if X is zero<br>
1 if X is positive
 
SGN is affected by the value of the [[BRConfig.sys]] [[RD]] specification. For instance, if RD were set to 6 (the default), the value returned by the following SGN function would be 1 (positive). But if RD were set to 3, the returned value would be 0:
 
===SHIFT===
 
The '''Shift''' [[internal function]]'s presence is syntactically accepted for [[System/23]] compatibility, but it does nothing. Programs should use the [[UprC$]] or [[LwrC$]] functions, or the [[U]] or [[L]] [[format specifications]] to force input into either uppercase or lowercase.
 
===SIN===
 
Sin(X)
 
The '''Sin''' [[internal function]] is a trigonometric function that returns the sine of X in radians.
 
====Related Functions:====
ATN, COS, EXP, LOG, PI and TAN.
 
===Sleep===
 
{{:Sleep}}
 
===SQR===
 
The '''Sqr''' [[internal function]] returns the square root of X.
 
====Comments and Examples====
PRINT SQR(16) will print the number 4.
 
====Technical Considerations====
# Attempting to take the square root of a negative number will produce an execution error ([[0403]]).
 
===Srch===
 
{{:Srch}}
 
===SRep$===
 
{{:SRep$}}
 
===Str$===
 
{{:Str$}}
 
===Sum(num-array)===
 
{{:Sum}}
 
===Tan===
 
{{:Tan}}
 
===Trim$===
 
{{:Trim$}}
 
===TIME$===
 
The '''Time$''' [[internal function]] returns the system time in the format hh:mm:ss.
 
====Comments and Examples====
00010 PRINT #255,USING 20: TIME$, DATE$
00020 FORM "Time: ",C 8,SKIP 1," Date: ",C 8
 
Lines 10 and 20 illustrate putting TIME$ and DATE$ as identifying information on a printed report.
 
====Related Functions:====
DATE$ and DATE
 
====Technical Considerations====
:1.) The time can be changed by the operator using the TIME command from Business Rules . On a multi-user system, these changes do not affect other workstations.
 
===UDim===
 
{{:UDim}}
 
==UnHex$==
 
{{:UnHex$}}
 
==Uprc$==
 
{{:UprC$}}
 
===Variable$===
 
{{:Variable$}}
 
===Val===
 
{{:Val}}
 
===VERSION===
 
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.
 
File VERSION capacity was increased to allow use of dates as version numbers.
 
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:
 
00100 OPEN #1:"NAME=CUSTOMER.DAT",INTERNAL,OUTIN
00110 IF VERSION(1)=1 THEN ! record length increased for C 5
00120 CLOSE #1:
00130 EXECUTE "COPY CUSTOMER.DAT WORK[WSID] -160 -N"
00140 EXECUTE "FREE CUSTOMER.DAT -N"
00150 EXECUTE "RENAME WORK[WSID] CUSTOMER.DAT -N"
00160 OPEN #1:"NAME=CUSTOMER.DAT",INTERNAL,OUTIN
00170 LET VERSION(1,2) ! update to version 2
00180 LET CUSTOMER=1 ! Changed flag
00190 END IF
00200 IF VERSION(1)=2 THEN ! change field length
00210 RESTORE #1:
00220 FORM1: POS 80,C 10,C 3 ! C 3 was C 5
00230 FORM2: POS 80,C 12,C 3
00240 LOOP1: READ #1,USING FORM1: A$,B$ EOF ENDLOOP1
 
00250 REWRITE #1,USING FORM 2: A$,B$
00260 GOTO LOOP1
00270 ENDLOOP1: VERSION(1,3) ! update complete to version 3
00280 LET CUSTOMER=1
00290 END IF
00300 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.
 
===WBPlatform$===
 
{{:WBPlatform}}
 
===WBVersion$===
 
{{:WBVersion$}}
 
===WSID$===
 
{{:WSID$}}
 
===Xlate$===
 
{{:Xlate$}}
 
<noinclude>
[[Category:Internal Functions]]
</noinclude>

Latest revision as of 18:25, 24 February 2014