If/Else/EndIf

Description:
The IF Flow Control statement allows a set of statements to be executed if the specified Condition is true and skipped if the Condition is false. Optionally a set of alternate statements can be executed if the Condition is false by using the 'Else' clause and supplying a set of statements. IF Flow Control statements can be placed within other Flow Control statements (nested).

Format:
If <condition>
 <true statements> (optional)
Else (optional)
 <false statements> (optional)
EndIf

Constructs:

<condition>

A phrase or set of phrases that can be evaluated to either TRUE or FALSE. For more information see Comparing Values.

<true statements>

Any set of Autoweb Statements or Functions to be executed if the Condition is TRUE. This section can be empty.

<false statements>

Any set of Autoweb Statements or Functions to be executed if the Condition is FALSE. This section can be empty.

Usage:
Use this statement to determine which Statements are to be executed based on some previous result. The Else with it's set of <false statements> is optional. The <true statements> are optional if the user is only interested in executing statements when the Condition is FALSE. The EndIf is always required. Placing If statements inside of other If statements (nested) is allowed.

Example 1:
Go to the My Yahoo! page and check to see if the User is signed –in. The ClickLinkWithText function will return TRUE if the link was present and successfully clicked on.

// Go to My Yahoo!
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

// Leave browser open for User
DisconnectBrowser()

Example 2:
Display the Yahoo! Search Page Document in the default Browser and ask the User to input a Search String, If the User clicks the Cancel button, close the Browser. Otherwise perform a Yahoo! Search.

// Create a variable to hold the Search String
String strSearch

// Open the Browser and go to the main Yahoo page
OpenBrowser (TRUE)
GoToDocument ('www.yahoo.com')

If InputBox('Search', 'Enter your search words', 'Words:#40R', 'strSearch', 'Ok') = 'CANCEL'
	// The User cancelled, close the Browser
	CloseBrowser ()
Else
	// Start the Yahoo! Search
	SetFieldWithLabel ('Search', strSearch)
	ClickButtonWithText ('Search')
	DisconnectBrowser ()
EndIf
Hosted by www.Geocities.ws

1