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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Checking within a subroutine 1

Status
Not open for further replies.

sergeys

MIS
May 22, 2007
55
US
Hi everybody!

I was trying to test if .Net Framework is functioning on a host computer, and came around something that I can’t understand.
Below, I am creating a bogus object, and trying to check it for false. If it is false, (which in this case it will always be), I want the if….then to catch it.
Can anybody explain why example1 does not work (does not dig into if….then), while examples 2 and 3 work fine.


'Example1
On Error Resume Next

Call MySub()

Sub MySub()
Set objRandom = CreateObject("BadObject")
If objRandom = False Then
WScript.Echo "Object could not be created"
End If
End Sub


'Example2
Call MySub()

Sub MySub()
On Error Resume Next
Set objRandom = CreateObject("BadObject")
If objRandom = False Then
WScript.Echo "Object could not be created"
End If
End Sub

'Example3
On Error Resume Next
Set objRandom = CreateObject("BadObject")
If objRandom = False Then
WScript.Echo "Object could not be created"
End If


Thank You for your help.
 
The error handling should be initialised in each procedure.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top