Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For...Next If/End if Problem

Status
Not open for further replies.

tavie

Technical User
Nov 23, 2001
79
0
0
US
I have a script logic problem that I am not sure how to fix without getting to elaborate.


here it is in a nutshelll

For %%%%%%%%%%%%
If err.number <> 0 then
wscript.echo err.number
goto next
end if
Next

If I encounter an error then I just want to process the next line in the For/Next loop. What would be the best method to do this without a bunch of extra lines of code ???
 
Before the loop you could put: On Error Resume Next
 
On Error Resume Next
For %%%%%%%%%%%%
If err.number <> 0 then
wscript.echo err.number
end if
Next


Maybe I misunderstood the question.... you can also use Exit For to break out of a For/Next loop.
 
Either something like this:
For %%%%%%%%%%%%
If Err.Number <> 0 Then
wscript.echo err.number
goto myLabel
End If
' regular stuff here
myLabel:
Next
Or like this:
For %%%%%%%%%%%%
If err.number <> 0 then
wscript.echo err.number
Else
' regular stuff here
End If
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
[tt] For %%%%%%%%%%%%
If err.number <> 0 then
wscript.echo err.number
'some other actions like err.clear
else
'do something when no error encounter
end if 'this end if is followed immediately by next
Next
[/tt]


 
The problem I am encountering is if there is any logic between the End if and Next statements, they will get processed even if an error occurs. I want those lines disregarded when an error is encountered.
 
Put your logic in the else body.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top