While/EndWhile
Description:
Format:
While <condition>
<true statements> (optional)
EndWhile
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 while the Condition is TRUE. This section can be empty. |
Usage:
Use While Statements to:
Process a list on a document
Process all the links on a document
Download all the Pictures on a page
Example 1:
Open and save each Link on a Document with the word 'Chapter' in it. Use an integer variable to control which Link is opened and saved. The ClickLinkWithText function will return TRUE if the link was present and successfully clicked on.
// This example assumes you have opened a Document with chapter links on it
// Create a Chapter Counter and start it at chapter 1
integer intChapter
intChapter = 1
// Open each Chapter and save it
// ClickLinkWithText will open the Chapter based on the intChapter counter
// When the Chapter does not exist, the While will stop executing
While ClickLinkWithText ('*Chapter*', intChapter)
// Chapter is displayed, ask the User if they want to save it
If MessageBox ('Save Chapter','Save this Chapter?', 'Question', 'Yes, No') = 'YES'
// Save the Documnet
SaveDocument('C:\Data\Chapter' + ToString (intChapter) + '.htm')
EndIf
// Return to the document with the Chapter links
GoBackDocument ()
// Get ready for the next chapter by adding 1 to the Chapter Counter
intChapter = intChapter + 1
EndWhile
Example 2:
// This example assumes you have opened a Document with chapter links on it
// Create a Chapter Counter and start it at chapter 1
integer intChapter
intChapter = 1
// Save each Chapter
// SaveLinkWithText will save the Chapter based on the intChapter counter
// When the Chapter does not exist, the While will stop executing
While SaveLinkWithText ('*Chapter*', 'C:\Data\Chapter' + ToString (intChapter) + '.htm', intChapter)
// Get ready for the next chapter by adding 1 to the Chapter Counter
intChapter = intChapter + 1
EndWhile
Example 3:
// This example assumes you have opened a Document with picture links on it
// Create a Link Counter and start it at link 1
integer intLink
intLink = 1
// Get each Link Address and save it if it is a Picture
// GetLinkWithText will return the Linked Document Address based on the intLink counter
// When the Link does not exist, the While will stop executing
strLink = GetLinkWithText ('*', intLink)
While Length(strLink) > 0
// See if Link is a Picture
If Pos(strLink, '.jpg') > 0
// It is a Picture file, save it
SaveDocument(strLink, 'C:\Data\Picture' + ToString (intLink) + '.jpg')
EndIf
// Get the next Link by adding 1 to the Link Counter
intLink = intLink + 1
strLink = GetLinkWithText ('*', intLink)
EndWhile