Statements
Statements provide a means of controlling your Scripts operation. The statements available are:
Syntax:
Exit Function
Exit While
Exit For
Allows for early exit from Functions and loops. If you put Exit Function in the main Function within an Event Script, the statement will cause the Script to finish at that point and return.
Syntax:
If condition Then
[code statements]
Else
[code statements]
End If
Allows different lines of code to be executed depending upon the result of checking the condition specified in the first line. If the condition is true then the lines of code immediately following the first line are executed, up to but not including, the Else line. If the condition is not true, then the lines following the Else line are executed instead, up to but not including the End If line. The End If line indicates the end of the If statement and must be included.
The Else statement can be omitted if not required in which case the lines of code following the If line will be executed up to the End If line, if the condition is true. If the condition is false, code execution will continue after the End If line.
Condition can be:
a = b (a equals b)
a <> b (a not equal to b)
a > b (a greater than b)
a >= b (a greater than or equal to b)
a < b (a less than b)
a <= b (a less than or equal to b)
where 'a' and 'b' can be variables, integers, text strings (contained in double quotes) or Functions.
Conditions can also be compounded, using the following logical operators:
not
and
or
xor
The order of precedence between these logical operators is as listed above, i.e. not takes highest precedence, but you can use brackets to force preference if required.
Examples:
If FirstName = "Ann" and LastName = "Brown" Then ...
If a = b and c < d Then ...
If FirstName = "Anna" or FirstName = "Olaf" Then ...
If not FirstName = "Billy" or Surname = "Singh" Then ...
If(a = b or c = d) and e = f Then ...
If(((a = b or c = d) and e = f) or g = h) and i = j Then ...
You can also nest If statements, e.g.:
If FirstName = "Ann" Then
If Surname = "Jones" Then
[code statements]
Else
[code statements]
End If
Else
If FirstName <> GetName() Then
[code statements]
Else
[code statements]
End If
End If
-
-
Once the appropriate lines of code have been executed, the Script will move on to run the line of code which immediately follows the End If line.
-
When matching strings, e.g. If FirstName = "Ann", whether or not the match is case-sensitive depends upon the setting of the Case Sensitive Script Property in the Project Properties. If set to True the match will be case-sensitive, if False it will be case-insensitive.
-
You can test for a Null variable using: If var = Null Then …
-
Syntax:
For variable = start To end [Step n]
[code statements]
[Exit For]
Next
Allows you to loop round the code lines included between the For and Next lines a specified number of times. 'Variable' specifies a variable which must be of integer type. 'start' and 'end' can be integers or integer variables and specify a range of numbers which determines how many times the loop will be performed. For example:
Dim NumVar
For NumVar = 1 To 10
[code statements]
Next
In this example, the loop will be performed 10 times. At the start of the loop, NumVar is set to the start value, in this case 1. Each time the Next line is executed the value in NumVar is increased by one. When NumVar exceeds the end value, i.e. in this case becomes 11, the loop stops and the Script moves on to the line of code immediately following the Next line.
You can change the size of the loop increment by adding the optional Step parameter which specifies the change to be applied when the Next line is reached. For example:
For NumVar = 1 To 10 Step 2
[code statements]
Next
will increase NumVar by 2 each time rather than 1, resulting in the loop being played 5 times instead of 10.
Negative values are allowed, e.g.:
For NumVar = 0 To -5 Step -1
[code statements]
Next
-
-
Exit For allows for early termination of the loop. The Script will abandon the loop and move on to the line immediately following the Next line.
-
For … Next statements can be nested.
-
Syntax:
While condition
[code statements]
[Exit While]
Wend
Allows you to loop round the lines of code between the While and Wend lines until the condition specified in the While line is not true. Possible conditions are the same as those defined in the If statement above.
-
-
Exit While allows for early termination of the loop. The Script will abandon the loop and move on to the line immediately following the Wend line.
-
While … Wend statements can be nested.
-
The Wend line marks the end of the Statement and must be included.
-
These Statements allow you to catch errors and determine what you want your Script to do should an error occur.
For full details refer to the
This Statement allows you to jump to a particular section within a Script, ignoring any intervening lines of code.
For full details refer to the