Script Variables (Release 3.5 and below)

Return to Introduction  Previous page  Next page

The script language has four types of variables: built-in variables, Windows environment variables, local variables and global variables.

Built-in Variables

Built-in variables are predefined. All built-in variables start with a dollar sign ($) and are all upper case. The following built-in variables are available.

 

$CLIPBOARD

replaced by any text on the Windows clipboard.

$COLS

replaced by the number of screen columns.

$COMPUTERNAME

computer name.

$CONVERT(screen_position,
{ROW | COL})

returns the row or column for the given screen position.
SetVar $CursorRow,$CONVERT($CURSOR,ROW)
SetVar $CursorColumn,$CONVERT($CURSOR,COL)

$CONVERT(row,col,POS)

returns the screen position relative to 1 for the given row and column.
SetVar $ScreenPosition,$CONVERT(24,80,POS)

$CRLF

replaced by a carriage return and line feed.

$CURSOR

replaced by the cursor position on the screen relative to 1 (row 1 column 1).

$DATE

date in the local date format.

$DATEDMY

date in DD/MM/YYYY format.

$DATEMDY

date in MM/DD/YYYY format.

$DATEYMD

date in YYYY-MM-DD format.

$FILEERROR

the return code of the last script file I/O operation.

$FILESTAT(file_path,
file_mode)

Returns an integer which is the status returned from an open request on the file. The file_mode should be one of the following:

modeRead
modeWrite
modeReadWrite

The returned integer will be one of the following standard Windows file exceptions:

0 = none. No error occurred.
1 = genericException. An unspecified error occurred.
2 = fileNotFound. The file could not be located.
3 = badPath. All or part of the path is invalid.
4 = tooManyOpenFiles. The permitted number of open files was exceeded.
5 = accessDenied. The file could not be accessed.
6 = invalidFile. There was an attempt to use an invalid file handle.
7 = removeCurrentDir. The current working directory cannot be removed.
8 = directoryFull. There are no more directory entries.
9 = badSeek. There was an error trying to set the file pointer.
10 = hardIO. There was a hardware error.
11 = sharingViolation. SHARE.EXE was not loaded, or a shared region was locked.
12 = lockViolation. There was an attempt to lock a region that was already locked.
13 = diskFull. The disk is full.
14 = endOfFile. The end of file was reached.
 
$FILESTAT is normally used in an if statement. For example:

If $FILESTAT("D:\test.txt",modeRead),EQ,2,FileNotFound:
If $FILESTAT("D:\test.txt",modeWrite),EQ,11,FileAlreadyOpen:

$LEFT(string,length)

Returns the specified number of characters from the left side of the string. Use this variable to extract characters from a string or another variable. string and/or length may be a variable.

$LEN(string)

Returns the length of the string. string may be a variable.

$LONGDATE

date in local long date format.

$MID(string,start[,length])

Returns the specified number of characters from the string starting with the character number specified in the start parameter. string, start and/or length may be a variable.

$OIA

replaced by the text in the Operator Information Area line on the terminal screen

$RIGHT(string,length)

Returns the specified number of characters from the right side of the string. Use this variable to extract characters from a string or another variable. string and/or length may be a variable.

$ROWS

replaced by the number of screen rows.

$SCREEN[(start[,length])]

replaced by the text at the specified location on the terminal screen.

where:

startis the starting position on the screen. Specify 1 to indicate row 1 column 1.
lengthis the number of characters to include.

 

start and/or length may be a variable. The ((start[,length])) parameter is optional. If you specify "$SCREEN" with no parameter, it is replaced by the text contents of the entire screen. If the(start[,length]) parameter is invalid, no substitution will take place and the variable will be treated as a literal.

 

$SCREEN[(top,left,bottom,right[,RECT])]

replaced by the text at the specified location on the terminal screen.

where:

topis the first row of the selection rectangle.
leftis the left column of the selection rectangle.
bottomis the last row of the selection rectangle.
rightis the right column of the selection rectangle.
RECTis optional and specifies that the selection area is a rectangle, not a string.

 

top, left, bottom, right and/or RECT may be a variable.

The (top,left,bottom,right) parameter is optional. If you specify "$SCREEN" with no parameter, the variable is replaced by the text contents of the entire screen. If the (top,left,bottom,right) parameter is invalid, no substitution will take place and the variable will be treated as a literal.

 


$SCREEN[(top,left,length)]

replaced by the text at the specified location on the terminal screen.

where:

topis the first row of the selection rectangle.
leftis the left column of the selection rectangle.
lengthis the number of characters to include.

 

top, left and/or length may be a variable.

The (top,left,length) parameter is optional. If you specify "$SCREEN" with no parameter, the variable is replaced by the text contents of the entire screen. If the (top,left,length) parameter is invalid, no substitution will take place and the variable will be treated as a literal.

$TIME

time in local time format.

$USERNAME

current logged on user name.

Windows Environment Variables

Windows environment variables can be used in script strings. Windows environment variables are enclosed in % signs and may be in upper or lower case. For example:

 

type "%COMPUTERNAME%"

 

Local Variables

Local variable names start with a dollar sign ($) and may be mixed case. Local variables are created dynamically by the AskFor and SetVar script commands which read text into a variable. Here are a couple of examples:

AskFor "Enter your userid and click OK",$NAME

SetVar  $NAME,"Sam Spade"

 

Most script commands accept a variable in place of literal data. The text contained in the variable is substituted for the variable when the script command is processed.

Global Variables

Global variable use the same syntax as a local variable. The variable name must start with a dollar sign ($) and may be mixed case. Global variables must be declared using the Global script command. The data in global variables is available within scripts called using the include script command. Local variables are not available to scripts called using the include command.

Variable Substring

You can extract a substring from a local variable, global variable or the built-in variable using the following format:

 

$variable[(start[,length])]

 

where:

startis the starting position within the variable.
lengthis the number of characters to include. length defaults to 1 if it is not specified.

 

start and/or length may be a variable.

For example, the following script types Joh on the screen.

 

SetVar $TEST,"John Doe"

type $TEST(1,3)

exit

 

Concatenated Variable Names

You can concatenate variable names. For example, $$SCREEN(1,4)$SCREEN(10,3) would result in a variable name $ followed by the contents of screen location 1-4 followed by the contents of screen location 10-12. Thus, if screen location 1-4 contained "WHIZ" and screen location 10-12 contained "KID" the result would be a variable name of "$WHIZKID".

 

See Also:

 

Script Command Summary

Using the Scripting Language


TN3270 Plus is continually being improved. To learn more about the latest enhancements, please review our Version History web page.