You can exit from a For/Next loop by using the Exit For statement. The following example searches the Global array names for the name "Fred". If it finds the name, it returns the index of the name in the array. Otherwise it returns -1. For example, if the names array is
Array ("Frank", "Helen", "Fred", "Linda")
Global names () As String
'The names array has been initialized and filled
'in other formulas
Dim i
formula = -1
'The UBound function returns the size of its array
'argument
For i = 1 to UBound (names)
If names (i) = "Fred" Then
formula = i
Exit For
End If
Next i
Another looping mechanism is the Do loop. A Do loop can be used to execute a fixed block of statement an indefinite number of time.
Note: The Do loops support an Exit Do statement to immediately jump out of the loop. The Exit Do statement is similar to the Exit For in For/Next loops.
| Seagate Software, Inc. http://www.seagatesoftware.com Please send comments to: techpubs@seagatesoftware.com |