mr_unreliable
Fri Jul 04 08:27:28 CDT 2008
vorpal wrote:
> Is there any way I can modify this so that the event handler is a
> class member?
>
hi Vorpal, I don't think you are going to get a constructive
answer to this query.
I tried your modifying your code, and using "GetRef" to connect
your subroutine to an object's events. That didn't work either.
I suspect that the scripting engine is looking for a "global"
subroutine name to connect to, rather than looking for a sub
name in the "class namespace". I would consider this to be a
"bug", but since microsoft has given up on maintaining vbs,
reporting bugs is futile.
As an alternative, you might consider restructuring your class
code as a "windows script component" (a.k.a. a "wsc" file).
WSC's are similar to class code, but structured a bit differently.
More to the point, a wsc file DOES allow for sinking events.
Instead of CreateObject, you use an object tag:
<object id="oATO" progid="wshAPIToolkit.ucATO" events="True"
reference="yes" />
Some scripters have objected to wsc's, because they (mistakenly)
believed that you must register them before using them. This
is not necessarily so. You can also use a wsc by simply loading
it directly from a file. If you are interested in this approach,
then here is some code, showing how to do that:
--- <code> ---
' ================================================
' === INSTANTIATE AN UNREGISTERED WSC COMPONENT ==
' ================================================
' (Note: this technique was suggested by Mike Harris
' (mvp - scripting), see news://microsoft.public.scripting.vbscript,
' entitled: "wsf vs wsc", and timestamped: 2002-03-26 19:10:05 PST).
'
' suggested syntax:
'
' set obj = getobject("script:component path#component id")
'
' where component path can be:
' c:\mypath\mywsc.wsc
' _or_ \\server\share\mypath\mywsc.wsc
' _or_
http://server/mysite/mypath/mywsc.wsc
'
' and, #component id is optional.
' You get the 1st component in the WSC by default.
' You only need #component id if there is more than one in
' the WSC, and you want some other component than the first...
'
' A more exhaustive discussion can be found in the Windows
' Script Component documentation, at the bottom of the page
' entitled: "Using a Script Component in an Application"
' --- end of discussion --------------------------
Sub Instantiate_LocalWSC(oWSC, sComponentFileName, sEventPrefix)
' get the path to the local directory...
Dim sLocalDir : sLocalDir = GetLocalDirectory()
Dim sComponentPath : sComponentPath = sLocalDir & sComponentFileName
' MsgBox(sComponentPath)
' go get the (wsc) object...
' Set oWSC = WScript.GetObject("script:" & sComponentPath,, _
sEventPrefix)
' uh-oh. It appears that this approach only works with the
' VBS getobject and not the wscript.getobject flavor.
Set oWSC = GetObject("script:" & sComponentPath)
' (step two:) connect the events, (after making sure you need it)...
if (sEventPrefix <> "") then WScript.ConnectObject oWSC, sEventPrefix
End Sub ' Instantiate_LocalWSC
--- <code> ---
cheers, jw
____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)