Comparing Values
AutoWeb has the ability to compare values and determine if the comparison is TRUE or FALSE. These comparisons are called Conditions. Conditions are used in Flow Control Statements to control which statements are executed, skipped, or repeated.
Conditions can be Simple (one phrase) or Complex (multiple phrases). Usually each Phrase in a Condition contains a Left Side, a Comparison Operator (=, >, or <), and a Right Side. Sometimes a phrase can consist of only a Left Side. Multiple Phrases are connected with Logical Operators (AND or OR). Precedence can be controlled with Parenthesis.
Simple Conditions (one phrase) that evaluate to TRUE:
1 + 2 = 3
4 > 3
3 * 3 < 12
'John' + ' ' + 'Smith' = 'John Smith'
Simple Conditions (one phrase) that evaluate to FALSE:
1 + 2 = 4
4 > 5
3 * 3 < 9
'Smith' + ',' + 'John' = 'John Smith'
Simple Conditions (one phrase) that only have a Left Side are really just shorthand for a normal Simple Condition: These can be used when the Left Side already evaluates to TRUE or FALSE. For example many of the functions in AutoWeb return TRUE or FALSE to let you know if the function was successful. In this case the shorthand method is acceptable. The following two conditions are equivalent:
ClickButtonWithText ('Sign On')
ClickButtonWithText ('Sign On') = TRUE
Complex Conditions (multiple phrases) that evaluate to TRUE. 'AND' means both Phrases on either side of the 'AND' must be TRUE. 'OR' means only one of the Phrases on either side of the 'OR' must be TRUE.
1 + 2 = 3 And 4 > 3
1 + 2 = 3 Or 4 > 5
'John' + ' ' + 'Smith' = 'John Smith' And 3 * 3 = 9
Complex Conditions (multiple phrases) that evaluate to FALSE.
1 + 2 = 3 And 2 > 3
1 + 2 = 4 Or 5 > 5
'John' + ' ' + 'Smith' = 'Smith, John' And 3 * 3 = 9
Parenthesis can be used in Complex Conditions (multiple phrases) to alter the normal left to right evaluation (Precedence) of the Condition. Phrases inside Parenthesis are evaluated first. Parenthesis are always used in pairs of Open and Close parenthesis, Parenthesis can be placed within other parenthesis (nested). The first example below evaluates to FALSE the second evaluates to TRUE.
1 + 2 = 3 Or 2 > 3 And 8 < 7
1 + 2 = 3 Or (2 > 3 And 8 < 7)
Using Conditions:
The above examples are mostly useless because 1 + 2 always equals 3, 8 is always greater than 7, etc. Conditions must be used in Flow Control Statements (If and While) and at least part of the condition needs to be changeable. Using Variables or Function Results in Conditions makes them evaluate differently based on the Variable or Function Result values. Below are useful examples of Conditions.
// Declare a result Variable
boolean boolResult
// Open Internet Explorer
OpenBrowser (TRUE)
// Navigate to the My Yahoo page
GoToDocument ('my.yahoo.com')
// See if you need to sign-in or not
// Click on the Link 'Sign In'. If the link was not there lb_Result will be FALSE
lb_Result = ClickLinkWithText ('Sign In')
If lb_Result = TRUE
// You need to sign-in
SetFieldWithLabel ('Yahoo! ID:', 'JohnSmith')
SetFieldWithLabel ('Password:', 'cactus')
ClickButtonWithText ('Sign In')
EndIf
// Disconnect Autoweb from Internet Explorer so that you can use the My Yahoo page
DisconnectBrowser()
Here is a shorter version of the same script. The ClickLinkWithText function is used directly in the If statement and the shorthand version of a Simple Condition is used.
OpenBrowser (TRUE)
GoToDocument ('my.yahoo.com')
// See if you need to sign-in or not
If ClickLinkWithText ('Sign In')
// You need to sign-in
SetFieldWithLabel ('Yahoo! ID:', 'JohnSmith')
SetFieldWithLabel ('Password:', 'cactus')
ClickButtonWithText ('Sign In')
EndIf
DisconnectBrowser()
See more examples in the
If and While documentation and in the example scripts provided with the AutoWeb install or on the support website.