Re: Problems with error handling using Windows Script Components in Visual Basic 6 by Tim
Tim
Tue Feb 22 08:21:26 CST 2005
Steve, I've distilled the problem I'm experiencing down to this example
:
The windows script component is comprised of 2 files:
MyTestComponent.wsc
---------------------------------
---------------------------------------------------------------
<?xml version="1.0"?>
<component>
<?component error="true" debug="false"?>
<registration
description="MyTestComponent"
progid="MyTestComponent"
version="1.00"
classid="{1566ff90-8fa0-4008-95d3-acc0aad5b79a}"
>
</registration>
<public>
<method name="CauseHavoc">
</method>
</public>
<script language="VBScript" src="MyTestComponent_Class.vbs">
<![CDATA[
Dim ThisMyTestComponent
Set ThisMyTestComponent = New MyTestComponentObj
function CauseHavoc()
ThisMyTestComponent.CauseHavoc
end function
]]>
</script>
</component>
---------------------------------------------------------------
and
MyTestComponent_Class.vbs
-------------------------------------------
---------------------------------------------------------------
Option Explicit
Class MyTestComponentObj
Public Function CauseHavoc()
MsgBox "in CauseHavoc"
Err.Raise vbObjectError+1,"MyTestComponent.
Method=CauseHavoc","Havac caused"
End Function
End Class
---------------------------------------------------------------
Now if I write a client vbs with the code below in, then, as expected,
I just see a message box of "In CauseHavoc"
However, if I put exactly the same code into a VB6 app (say a forms
load method), then I get the same message box, but then I get a run
time error from the err.raise, despite the calling code having on error
resume next / on error goto 0 around the call to the script component
ClientOfMyTestComponent.vbs
---------------------------------------------------------------
Dim MyObj
Set MyObj = CreateObject("MyTestComponent")
On Error Resume Next
MyObj.CauseHavoc
On Error Goto 0
---------------------------------------------------------------
Try it out. Weird huh.. or have I missed something!?