Variable Declaration

Action

Declares a variable.

Syntax

[scope] [share] data-type variable-id [ = expr ] [, variable-id [ = expr]] ...
Variable Description
scope Optional: Either public (the default) or private. Private declarations are available only in the file in which they occur. Public declarations can be accessed from other files through a use statement. You can specify the scope only if the declaration is global, which means that the declaration is not located within a function, a window, or a winclass declaration.
share Optional: Indicates that the variable is shared by multiple threads. Access to shared variables is controlled with the access statement.
data-type The data type of the variable.
variable-id An identifier that specifies the name of the variable.
expr Optional: An expression that evaluates the initial value of the variable. The value must be compatible with the type of the variable. If you try to use a variable before the value of the variable is set, 4Test raises an exception.

Notes

  • To pass global variables between .t files in a project, declare the variables in the frame.inc file of the project.
  • If your scripts spawn multiple threads for parallel processing, keep in mind that all threads have equal access to global variables. To prevent multiple threads modifying a variable at the same time, declare the variable as shared, using the share keyword. A thread can request access to shared variables using the access statement.
  • Concurrent access to a local variable or a non-shared global variable by parallel threads might generate unpredictable results. Use shared variables wherever the potential for conflict exists.

Examples

[ ] INTEGER iTestNum = 0
[-] LIST OF STRING lsTerriers = {...}
	[ ] "Airedale"
	[ ] "Irish"
[ ] BOOLEAN bDone = FALSE, bFound = FALSE
[ ] public ARRAY[7] OF STRING asWeekDay
[ ] ANYTYPE aWhoKnows
[-] type NAME is record
	[ ] STRING sFirst
	[ ] STRING sLast
[-] NAME Name = {...}
	[ ] "Maxwell"
	[ ] "Smart"