Script Variables (Release 3.6 and above)

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.

 

$ARG0

full path of the script file from the command line.

$ARG1, ARG2, ...

arguments from the command line.

$ARGC

count of arguments on the command line.

$CLIPBOARD

replaced by any text on the Windows clipboard.

$COLS

replaced by the number of screen columns.

$COMPUTERNAME

computer name.

$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.

$LONGDATE

date in local long date format.

$OIA

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

$PARENTSCRIPT

name of the calling script or "<none>".

$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.

$SCRIPTFOLDER

the full path of the folder containing the currently active script.

$SCRIPTNAME

name of currently active script.

$SESSIONNAME

name of session the script is running in or "<none>".

$TIME

time in local time format.

$USERNAME

current logged on user name.

$VERSION

The TN3270 Plus version number as an integer. For example release 3.6.0 = 3600 and release 3.6.1 = 3601.

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%)

 

Windows User Environment Variables

Windows user environment variables can be used in script strings. Windows user environment variables are enclosed in % signs and may be in upper or lower case. Windows user environment variables can be created with the TN3270 Plus script SetUserEnv command. Windows User Environment Variables are accessible from the programs external to TN3270 Plus like Windows PowerShell or VBScript.

 

Local Environment Variables

Local Environment variables can be used in script strings. Local environment variables are enclosed in % signs and may be in upper or lower case. Local environment variables can be created with the TN3270 Plus script SetEnv command. Use Local Environment Variables to pass data from one TN3270 Plus script to another.

Local Variables

Local variable names start with a dollar sign ($) and may be mixed case. Local variables are created dynamically by an assignment statement. For example:

$Name = AskFor("Enter your userid and click OK")

$CursorRow = Convert($Cursor,ROW)

$CursorColumn = Convert($Cursor,COL)

 

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.

 

$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.