Be careful when using @ERROR at the start of loops if you don't precede it with the function.

Take this for example, exactly the same procedure run twice:
Code:
$Index = 0

While @Error=0
$KeyName=ENUMKEY("HKEY_CURRENT_USER\Console\", $Index)
If @ERROR = 0 ?
"Name found on first pass: $KeyName"
$Index=$Index+1
EndIf
Loop

$Index = 0
While @Error=0
$KeyName=ENUMKEY("HKEY_CURRENT_USER\Console\", $Index)
If @ERROR = 0 ?
"Name found on second pass: $KeyName"
$Index=$Index+1
EndIf
Loop



The problem is that the second pass will not display any results.

The reason is that @ERROR from the first loop is still set, so that the second loop fails instantly.

In a more complex function this can be a bugger to spot.

The solution is to clear the error status before starting the loop:
Code:
$Index=Execute("Exit 0") ; Initialise index and clear error status

While @Error=0
$KeyName=ENUMKEY("HKEY_CURRENT_USER\Console\", $Index)
If @ERROR = 0 ?
"Name found on first pass: $KeyName"
$Index=$Index+1
EndIf
Loop

$Index=Execute("Exit 0") ; Initialise index and clear error status
While @Error=0
$KeyName=ENUMKEY("HKEY_CURRENT_USER\Console\", $Index)
If @ERROR = 0 ?
"Name found on second pass: $KeyName"
$Index=$Index+1
EndIf
Loop



[EDIT]
Spooky. I'll have to type quicker.
[/EDIT]


Edited by Richard H. (2004-05-24 04:42 PM)