Runtime verbs and functions

Top  Previous  Next

 

The following list is a summary of verbs and functions present in the UnForm runtime engine and are commonly used in UnForm applications.  Note that all functions accept an ",err=linelabel" or "err=next" argument, and all verbs accept the same after any parameters, to branch if an error occurs.  Optional arguments are shown inside braces {}.

 

 

ASC(string)

Returns the ASCII numeric value (0-255) of the first character of string.

ATH(string)

Returns a binary equivalent of a human readable hex string.  ATH("1B") returns an escape character.

BIN(integer,length)

Returns a binary integer representation of the specified length.  The inverse function of this is the DEC() function.

BREAK

Breaks out of a loop structure.  Equivalent to EXITTO linelabel if linelabel is the line after the closing WEND or NEXT.

CHR(integer)

Returns a character string whose ASCII value is integer, between 0 and 255.  CHR(27) returns an escape character.

CONTINUE

Executes the next iteration of a loop structure.  Equivalent to GOTO linelabel, if linelabel is the closing WEND or NEXT.

CVS(string,arg)

Returns a converted string according to the cumulative value of the integer arg.  Values: 1=strip leading spaces, 2=strip trailing spaces, 4=uppercase, 8=lowercase, 16=non-printable characters to spaces, 32=multiple spaces to single spaces.  CVS(a$,3) trims both leading and trailing spaces.

DATE(julian {,time} {:mask})

DTE(julian {,time} {:mask})

Returns a human readable date and/or time, based on the Julian date (see the JUL() function), a decimal time (hour and fraction of hour – 12.5=12:30PM), and a format mask.  The mask can contain combinations of placeholder characters and modifiers.  The placeholders are %M=month, %D=day, %Y=year, %H=hour (24 hour clock), %h=hour (12 hour clock), %m=minute, %s=second, %p=AM/PM.  Modifiers include z=zero fill, s=short text, l=long text.  Examples on June 30, 1999 at 1:30 in the afternoon: date(0) returns "06/30/99", date(0:"%Ml %D, %Yl") returns "June 30, 1999", date(0,tim:"%hz:mz %p") returns "01:30 PM".

DEC(string)

Returns the decimal conversion of the binary integer in string.  The counterpart to the BIN() function.  To treat string as an unsigned integer, you should use the form DEC($00$+string).

DIM string(length {,char})

Returns a string of length size, of spaces or the specified char character.

DIM name[dim1{,dim2{,dim3}}]

Creates a numeric or string array variable.  Dimensions can be simple integers, indicating an index range of 0..dim, or two integers separated by a colon, like 1:12.

DIR("")

Returns the current disk directory.  On Windows, DIR(driveletter) will return the current directory for the specified disk drive.

EPT(number)

Returns the 10's exponent value of number.  EPT(100)=3, EPT(12)=2.

ERASE filename

Erases a file.  Obviously, care should be taken to only erase temporary work files.

EXITTO linelabel

Exits a loop structure (current level only, in nested structures) and jumps to the specified linelabel.

FBIN(number)

I3E(number)

Returns a 64-bit IEEE number in natural left to right ordering.

FDEC(string)

I3E(string)

Returns the decimal value of a 64-bit IEEE number.

FID(channel)

Returns a file identification string for the file opened on channel.  For devices, just the device name is returned.  For files, the first byte indicates the file type ($00$=indexed, $01$=serial, $02$=keyed, $03$=text, $04$=program, $05$=directory, $06$=mkeyed, etc.)  You can verify a file is a plain text file like this: test$=fid(filechan); if test$(1,1)=$03$ then x$="text file".

FILL(integer{,string})

DIM(integer{,string})

Returns a string if integer length, made up of successive iterations of string, or spaces if no string is provided.  FILL(7,"abc") will return "abcabca".

FIN(channel)

Returns additional file information not found in the FID() function.  A common use of this function is to determine file size, which is stored as a binary integer in the first four bytes.  To get the length of a file: x$=fid(filechannel); length=dec($00$+x$(1,4)).  Additional potentially useful information can be found as well.  See the language reference manual for more details.

FOR numvar=start TO end {STEP increment}

Initiates a loop, using a numeric variable initialized to start the first pass through the loop, incrementing by 1 or the specified increment, which can be negative, until the variable exceeds (or goes below in the case of a negative increment) end.  The statements following this command, until a NEXT numvar statement, are executed.  The loop can be broken from with the BREAK or EXITTO verbs.

FPT(number)

Returns the fractional portion of a number.  FPT(100.66) returns .66.

GOSUB linelabel

Jumps to the specified linelabel.  Statements will be executed until a RETURN verb is encountered, and execution will return to the statement after the GOSUB.

GOTO  linelabel

Jumps to the specified linelabel.

HTA(hexstring)

Returns a human readable hex string of hexstring.  HTA(CHR(2)) returns "02".  HTA("0") returns "30".

IF test THEN statement(s) {ELSE statement(s)} {END_IF or FI}

Conditionally executes statements. test must be a simple expression that produces a Boolean or numeric result (0=false, non-0=true).  Multiple statements can follow the THEN or ELSE clause by separating them with semi-colons.  Statements following a END_IF are executed without regard to the condition of the last IF test.  Nested IF statements are accepted without practical limit.

IF test {THEN{:}}

statements

END IF

A block (multiline) IF statement ends with an optional THEN and colon character, followed by the lines that execute if the test is true, and ends with END IF.

INT(number)

Returns the integer portion of a number.  INT(99.645)=99.

JUL(year,month,day)

Returns the Julian integer of the specified date elements.  The year should be specified, if possible, as a 4-digit year.  Otherwise the function will assume a century of 1900.  The complement of this function is the DATE() function.

LEN(string)

Returns the length of the string.

LET var=value{,var=value…}

Assigns variables to values.  The variables can be numeric, string, or array variables.  The values can be any compatible numeric or string expression.  LET is implied when an assignment is performed in context.  "LET a=1" and "a=1" are equivalent.

MASK(string{,regexpr})

MSK(string{,regexpr})

Returns the position where a regular expression pattern was found in the string, or 0 If not found.  If regexpr is not specified, then the last regexpr used is re-used.  This provides a performance benefit for repeated uses of the same regexpr.  The length of the string matched is returned by the TCB(16) function.

MAX(num{,num…})

Returns the largest number found in the list of nums.

MIN(num{,num…})

Returns the smallest number found in the list of nums.

MOD(num1,num2)

Returns the remainder of dividing num1 by num2.  MOD(4,3)=1, MOD(6,3)=0.

NUM(string)

Returns the decimal value of a string, assuming the string is a well-formatted value containing digits, a single optional period (decimal point), and a single optional leading hyphen (minus sign).  Other punctuation or characters will return an error.  NUM("-12.5") returns 12.5.  NUM("1,456") results in an error.

ON integer GOTO|GOSUB linelabel{,linelabel…}

Branches to one of the indicated line labels based on the value of integer.  If integer is 0 or less, branch to the first label, 1 to the second, 2 to the third, and so on.  The last label is used for integer values greater than that of the last label.

OPEN(integer{,err=linelabel|next}{,isz=integer}) string

Opens the file named in string on channel integer.   To open a file in binary mode regardless of the file type, specify a block size with the ",isz=-1" option.

PAD(string$,len[,pad_code][,char$])

Returns the string truncated or padded to the length specified.  The pad_code can be 0 for left padding, or 1 for right padding, and the specified char$ character is used for padding.  The default is right padding and a space pad character.

POS(string1 relation string2 {,increment {,occurrence}})

Scans string2 for a substring having the specified relation to string1.  POS("B"="ABC") returns 2.  POS("B"<"ABC") returns 3.  The string can be searched in even character increments: POS("02"="002002",2) will return 5, since the second and third characters, though matching the search string, are not located at an increment boundary.  If the string is not found, or the requested relation, increment, and occurrence cause the string to not be found, the function returns 0.

PRINT(channel) value {,value…}{,}

Prints a series of values, numeric and/or string, to the file channel specified.  A line-feed character is added to the channel unless the last character of the statement is a comma.

READ{ RECORD}(channel {,options} ) variable {,variable…}

Reads data from the specified channel into the specified variables, looking for field terminator characters to delimit variables.  Field terminators include line-feeds, carriage returns, and nulls.  Valid options include "err=linelabel", "end=linelabel", "siz=blocksize". "key=keystring", "ind=index", and "dom=linelabel".  For intrinsic keyed files, use the key= or ind= options to read specific records.  For text files, use READ to process line-feed delimited files, but be aware that carriage return characters act as field separators.  To read text files as binary files, use READ RECORD with a "siz=" option.

REM

Places a non-executing remark line in the code.  In UnForm, you can also use a # character.

RETRY

Retries the statement that caused the last error branch to be taken.

RETURN

Returns from a GOSUB branch.

RND(integer)

Returns a pseudo-random number.  The random number sequence can be re-seeded by providing a negative integer, so it is common at startup (like in a prejob code block) to seed the RND function with a variable number, such as MOD(JUL(0,0,0)+INT(TIM*10000),32000). The integer can be a number from –32767 to +32767.  Positive numbers return a random integer from 0 to integer-1.  If integer is 0, a random number between 0 and 1 is returned.

ROUND(number,precision)

Returns number, rounded to precision.  ROUND(1.566,2)=1.57.  ROUND(100.83,0) returns 101.

SCALL(string)

SYS(string)

Executes the operating system command in string.  Returns the result code provided by the operating system.  Use this function to interface with the operating system or external commands.   This is an alternative to opening a pipe to a command.

SETERR linelabel

Provides a generic error handler to catch errors not trapped by err=linelabel branches in functions and verbs.  UnForm also adds error handling code to code blocks, and reports errors in a job error file (temp/jobno.err in the server directory).

SGN(number)

Returns a 1, 0, or –1, depending on the sign of number.

STBL(string1{,string2})

GBL(string1{,string2})

Returns and/or sets the global string table value named string1.  If string2 is present, then the string table is set to string2.  In both cases, the value is returned.  If string1 has not been set, STBL(string1) will result in an error (trappable with err=linelabel, of course).

STR(number{:mask})

STR(string{:mask})

Converts a number to a string, optionally formatted with a mask.  The mask can contain any text, plus the following placeholder characters: 0=zero filled digit, #=space filled digit,  "."=decimal point, ","=thousands separator, -, (, ), and CR for negative numbers.  STR(99.91:"0000.00") returns "0099.91".  STR(19093.255:"###,##0.00") returns "19,093.26".

STRING filename{,err=label}

SERIAL filename{,err=label}

Creates a text file of the name specified.  Use either a string variable or expression, or a quoted literal string.

 

Examples: STRING "/tmp/test.txt" or STRING "/tmp/"+str(dec(info(3,0)))+".txt",err=next.

TCB(integer)

Returns task control information.  Commonly used integer values include: 10=last operating system error code, 16=length of MSK() function match, 20 for number of arguments passed to an ENTER command.

TIM

Numeric variable that returns the decimal time of day, from 0.0 to 23.99.

UNT

Numeric variable that returns the next available file channel number.

WHILE condition…WEND

Looping construct that performs statements between WHILE and WEND statements as long as condition is true or non-zero.

WRITE {RECORD} (chan,options)data

Writes data to a file.  Numerous options are available, some depending on the type of file.  See the full programming documentation available on www.pvxplus.com for more details.

 

 

Lexical Substitutions

 

With the change in Version 6 to the ProvideX run-time engine, it is possible that some BBx syntax in code blocks will be incompatible.  For the most part, the lexical substitutions automatically performed by UnForm will handle any differences, with the exception of direct I/O to BBx data files, which can often be handled with the bbxread() function.  However, if any additional substitutions are required, they can be entered into a user-defined text file called uflexsub.usr.

 

The format for the lines in this file is simply bbxsyntax=pvxsyntax.  An example is provided in uflexsub.txt, which is a file that provides some standard syntax substitutions that the internal lex capabilities do not support.  You can add your own by simply creating uflexsub.usr and adding lines.