Variables may be declared using the
Public statements. The syntax is:
Dim VariableName As [data type]
Private VariableName As [data type]
Public VariableName As [data type]
For example, to declare a variable of type String and assign a value to that variable, you might type:
Dim carmake As String
carmake = "Honda"
Alternatively, the following code creates a variable of the type String and assigns a value to that variable. The variable
has the type String because the compiler knows that "Honda" must be a String. This code achieves the same result as the preceding
example and in most cases, the following example is preferable:
Dim carmake = "Honda"
If you declare a variable without a type in a script,
Silk Test Workbench displays a message stating that no type was specified for the variable. The compiler assumes that the variable is of type
Object by default.
It is recommended to declare all variables in scripts. Not declaring variables can cause errors. For example, a spelling mistake
can cause two variables to exist instead of one, causing your script to malfunction. This is a very common error but often
difficult to diagnose.
Note: You do not have to manually force variable declaration. Variable declaration is forced by default. You cannot use the
Option Explicit statement to manually disable the enforcement of variable declaration in a script, because
Silk Test Workbench performs hidden automated imports before any script is started, and the
Option Explicit statement requires to be set before the first import.