Keyword Reference

For...In...Next

Enumerates elements in an Object collection or an array

For <$Variable> In <expression>
    statements
    ...
Next

 

Parameters

Variable A variable to which an element is being assigned
expression Must be an expression resulting in an Object, or an Array with at least one element

 

Remarks

The Variable will be created automatically with a LOCAL scope, even when MustDeclareVars is on.
If the expression is an Object collection with no elements, the loop will be skipped and the Variable will contain an empty string.
If the expression is not an Object nor an Array, the script stops with an error, unless a COM Error handler had been configured.

For...In...Next statements may be nested.

 

Related

With...EndWith, ObjEvent (COM Error handler)

 

Example


;Using an Array
Dim $aArray[4]

$aArray[0]="a"
$aArray[1]=0
$aArray[2]=1.3434
$aArray[3]="test"

$string = ""
FOR $element IN $aArray
    $string = $string & $element & @CRLF
NEXT

Msgbox(0,"For..IN Arraytest","Result is: " & @CRLF & $string)

;Using an Object Collection

$oShell = ObjCreate("shell.application")
$oShellWindows=$oShell.windows

if Isobj($oShellWindows) then
  $string=""

  for $Window in $oShellWindows
    $String = $String & $Window.LocationName & @CRLF
  next

  msgbox(0,"","You have the following windows open:" & @CRLF & $String)
else

  msgbox(0,"","you have no open shell windows.")
endif