event handling in Script Control 
Author Message
 event handling in Script Control

Suppose I have an ActiveX object firing an event "OnConnect". How can I
catch that Event with VBScript in the Script Control?

Something like this ??

Dim x
x = CreateObject("MyActiveX")

Sub x_OnConnect
    MsgBox "you succeeded"
End Sub



Sat, 03 Mar 2001 03:00:00 GMT  
 event handling in Script Control
Should be working. Worked for me at least, when handing code objects to
the Script Control with AddObject().

Ralf Westphal

Quote:

>Suppose I have an ActiveX object firing an event "OnConnect". How can I
>catch that Event with VBScript in the Script Control?

>Something like this ??

>Dim x
>x = CreateObject("MyActiveX")

>Sub x_OnConnect
>    MsgBox "you succeeded"
>End Sub



Sun, 04 Mar 2001 03:00:00 GMT  
 event handling in Script Control
Did you move the control into connected state?

Eric

Quote:

>Suppose I have an ActiveX object firing an event "OnConnect". How can I
>catch that Event with VBScript in the Script Control?

>Something like this ??

>Dim x
>x = CreateObject("MyActiveX")

>Sub x_OnConnect
>    MsgBox "you succeeded"
>End Sub



Sun, 04 Mar 2001 03:00:00 GMT  
 event handling in Script Control
Kurt, if your code snippet cannot work as passed to ScriptControl.
You should create an object at host side, then add it to ScriptControl namespace
with:

*Assuming you use VB app as host:*

x = CreateObject("MyActiveX")
ScriptControl.AddObject("x", x)
ScriptControl.State = Connected

*in script:*

Sub x_OnConnect
    MsgBox "you succeeded"
End Sub

Regards,
Captain Cerebrum
Innovative stuff for IE4 and HTML Help authoring
http://www.meadroid.com/wpm/
FREE ScriptX: Dynamic Event Binding, Printing
http://www.meadroid.com/scriptx

Suppose I have an ActiveX object firing an event "OnConnect". How can I
catch that Event with VBScript in the Script Control?

Something like this ??

Dim x
x = CreateObject("MyActiveX")



Sun, 04 Mar 2001 03:00:00 GMT  
 event handling in Script Control
Remember you need to use the "set" keyword when assigning an object.  Common
error -- hard to track down.

Eric

Quote:

>Kurt, if your code snippet cannot work as passed to ScriptControl.
>You should create an object at host side, then add it to ScriptControl
namespace
>with:

>*Assuming you use VB app as host:*

>x = CreateObject("MyActiveX")
>ScriptControl.AddObject("x", x)
>ScriptControl.State = Connected

>*in script:*

>Sub x_OnConnect
>    MsgBox "you succeeded"
>End Sub

>Regards,
>Captain Cerebrum
>Innovative stuff for IE4 and HTML Help authoring
>http://www.meadroid.com/wpm/
>FREE ScriptX: Dynamic Event Binding, Printing
>http://www.meadroid.com/scriptx


>Suppose I have an ActiveX object firing an event "OnConnect". How can I
>catch that Event with VBScript in the Script Control?

>Something like this ??

>Dim x
>x = CreateObject("MyActiveX")



Mon, 05 Mar 2001 03:00:00 GMT  
 event handling in Script Control
Sure thing. Shame on me, I've blindly copied a snip from original message ;-)
-cap.


Tue, 06 Mar 2001 03:00:00 GMT  
 event handling in Script Control

Quote:

>Kurt, if your code snippet cannot work as passed to ScriptControl.
>You should create an object at host side, then add it to ScriptControl
namespace
>with:

>*Assuming you use VB app as host:*

>x = CreateObject("MyActiveX")
>ScriptControl.AddObject("x", x)
>ScriptControl.State = Connected

>*in script:*

>Sub x_OnConnect
>    MsgBox "you succeeded"
>End Sub

Yes, I know I can solve it this way. But I want to create the object within
the script control. If that control exposes events I want to handle them
within the same environment. Is this possible?

kurt



Fri, 09 Mar 2001 03:00:00 GMT  
 event handling in Script Control
Still, not all classes propagate events to the script... One such class is
InternetExplorer.Application. Another is Excel.Application.8...

Costas Andriotis
http://users.forthnet.gr/ath/costasan/index.htm


Quote:


>>Kurt, if your code snippet cannot work as passed to ScriptControl.
>>You should create an object at host side, then add it to ScriptControl
>namespace
>>with:

>>*Assuming you use VB app as host:*

>>x = CreateObject("MyActiveX")
>>ScriptControl.AddObject("x", x)
>>ScriptControl.State = Connected

>>*in script:*

>>Sub x_OnConnect
>>    MsgBox "you succeeded"
>>End Sub

>Yes, I know I can solve it this way. But I want to create the object within
>the script control. If that control exposes events I want to handle them
>within the same environment. Is this possible?

>kurt



Sat, 10 Mar 2001 03:00:00 GMT  
 event handling in Script Control
"Excel.Application" and "InternetExplorer.Application" objects don't support
IProvideCalssInfo[2] interface, so there is no way to recognize the source
interface to bind to.
In ScriptX, we solved this with NewEventSinkByName method. The name of default
event
set interface could be retrieved with OleView
(http://www.microsoft.com/com/resource/OVI386.EXE)
For "InternetExplorer.Application" -- "DWebBrowserEvents2"
For "Excel.Application" -- "AppEvents"

Here is an example for Excel.

var objXL;
objXL = new ActiveXObject("Excel.Application");
objXL.Visible = true;

var factory = new ActiveXObject("ScriptX.Factory");
var sink = factory.NewEventSinkByName(objXL.Application, "AppEvents");
sink("NewWorkbook") = xl_NewWorkbook;

WScript.echo("Adding new Workbook!");
objXL.Workbooks.Add();

WScript.echo("Excel: Quit!");
objXL.Quit();

sink.Unadvise()
WScript.echo("WScript: Quit!");
WScript.Quit();

function xl_NewWorkbook(Wb) {
  WScript.echo("NewWorkbook Event!");

Quote:
}

Regards,
Captain Cerebrum
Innovative extensions for IE4 and HTML Help authoring
http://www.meadroid.com/wpm/
FREE ScriptX: Dynamic Event Binding, Printing
http://www.meadroid.com/scriptx

Still, not all classes propagate events to the script... One such class is
InternetExplorer.Application. Another is Excel.Application.8...

Costas Andriotis
http://users.forthnet.gr/ath/costasan/index.htm



Sat, 10 Mar 2001 03:00:00 GMT  
 event handling in Script Control
There is an unwritten rule that implementation classes of a coclass must NOT
be shared.  This allows you to determine the event sink of an IDispatch at
run-time even if IProvideClassInfo is not supported.  Follow these steps:

1) With the IDispatch pointer use IDispatch::GetTypeInfo to get the
ITypeInfo pointer.
2) Get the GUID of the ITypeInfo.
3) Get the containing ITypeLib.
4) Inspect all the ITypeInfos which are coclasses.  Find the coclass that
has a default (non-source) implementation type with the same GUID.  Once the
coclass is found, find for the default, source implementation type.  That is
the event source.

The "Invoke Method Library" (available for free from Polar Engineering at
http://www.kenai.com/vb4tools/invmeth.htm) uses this approach.

set xl = CreateObject("Excel.Application")
set iml = CreateObject("WinWrap.InvokeMethodLibraryObject")
set sink = iml.CreateSinkObject(Me, xl)
sink("xl_") = True ' enable sink
xl.Workbooks.Add
sink("") = False ' disable sink
xl.Quit

Sub xl_NewWorkbook(Wb)
   MsgBox "NewWorkbook"
End Sub

Tom Bennett
Polar Engineering and Consulting

http://www.kenai.com

Quote:

>"Excel.Application" and "InternetExplorer.Application" objects don't
support
>IProvideCalssInfo[2] interface, so there is no way to recognize the source
>interface to bind to.
>In ScriptX, we solved this with NewEventSinkByName method. The name of
default
>event
>set interface could be retrieved with OleView
>(http://www.microsoft.com/com/resource/OVI386.EXE)
>For "InternetExplorer.Application" -- "DWebBrowserEvents2"
>For "Excel.Application" -- "AppEvents"

>Here is an example for Excel.

>var objXL;
>objXL = new ActiveXObject("Excel.Application");
>objXL.Visible = true;

>var factory = new ActiveXObject("ScriptX.Factory");
>var sink = factory.NewEventSinkByName(objXL.Application, "AppEvents");
>sink("NewWorkbook") = xl_NewWorkbook;

>WScript.echo("Adding new Workbook!");
>objXL.Workbooks.Add();

>WScript.echo("Excel: Quit!");
>objXL.Quit();

>sink.Unadvise()
>WScript.echo("WScript: Quit!");
>WScript.Quit();

>function xl_NewWorkbook(Wb) {
>  WScript.echo("NewWorkbook Event!");
>}

>Regards,
>Captain Cerebrum
>Innovative extensions for IE4 and HTML Help authoring
>http://www.meadroid.com/wpm/
>FREE ScriptX: Dynamic Event Binding, Printing
>http://www.meadroid.com/scriptx


>Still, not all classes propagate events to the script... One such class is
>InternetExplorer.Application. Another is Excel.Application.8...

>Costas Andriotis
>http://users.forthnet.gr/ath/costasan/index.htm



Sat, 10 Mar 2001 03:00:00 GMT  
 event handling in Script Control
Thanks for info, Tom. Invoke Method Library is very good, I didn't know about it
before.
I'm using similar approach, looking though for given name globally in typelib.

What's interesting with you code:

set sink = iml.CreateSinkObject(Me, xl)
sink("xl_") = True ' enable sink
...
sink("") = False ' disable sink

How do you make sink object to know about script Dispatch, to invoke
xl_NewWorkbook later?
-cap.



Sun, 11 Mar 2001 03:00:00 GMT  
 event handling in Script Control
Now I see: CreateSinkObject(*Me*, xl)
-cap.


Sun, 11 Mar 2001 03:00:00 GMT  
 event handling in Script Control
Indeed, the library is very good. I'm still having problems releasing
references to Excel though. It's probably due to xl itself, but I'm not
sure... IE appears fine.

In Tom's script, xl is still running invisibly when I quit the application.
I also have to set Sink to nothing to release the XL references. This is not
needed in WSH, but apparently is needed in my script control host app.

There are though some quirks: if you apply the process to a class that
doesn't need it (e.g. MS Agent or MS Word, events will fire twice (or more,
if you repeat the process). Perhaps Tom can fix this?

Costas Andriotis
http://users.forthnet.gr/ath/costasan/index.htm

Quote:

>Now I see: CreateSinkObject(*Me*, xl)
>-cap.



Mon, 12 Mar 2001 03:00:00 GMT  
 event handling in Script Control
I cannot get this code sample to work - please post some working code.

Russell


Quote:
>Remember you need to use the "set" keyword when assigning an object.
Common
>error -- hard to track down.

>Eric


>>Kurt, if your code snippet cannot work as passed to ScriptControl.
>>You should create an object at host side, then add it to ScriptControl
>namespace
>>with:

>>*Assuming you use VB app as host:*

>>x = CreateObject("MyActiveX")
>>ScriptControl.AddObject("x", x)
>>ScriptControl.State = Connected

>>*in script:*

>>Sub x_OnConnect
>>    MsgBox "you succeeded"
>>End Sub

>>Regards,
>>Captain Cerebrum
>>Innovative stuff for IE4 and HTML Help authoring
>>http://www.meadroid.com/wpm/
>>FREE ScriptX: Dynamic Event Binding, Printing
>>http://www.meadroid.com/scriptx


>>Suppose I have an ActiveX object firing an event "OnConnect". How can I
>>catch that Event with VBScript in the Script Control?

>>Something like this ??

>>Dim x
>>x = CreateObject("MyActiveX")



Mon, 19 Mar 2001 03:00:00 GMT  
 event handling in Script Control
This is not a real sample, just a prototype.
The real code depends on what AX you use, particular ScriptControl host, etc.
If you posted your case, we might be able to suggest what's wrong.
-cap.

I cannot get this code sample to work - please post some working code.

Russell


Quote:
>Remember you need to use the "set" keyword when assigning an object.
Common
>error -- hard to track down.

>Eric


>>Kurt, if your code snippet cannot work as passed to ScriptControl.
>>You should create an object at host side, then add it to ScriptControl
>namespace
>>with:

>>*Assuming you use VB app as host:*

>>x = CreateObject("MyActiveX")
>>ScriptControl.AddObject("x", x)
>>ScriptControl.State = Connected

>>*in script:*

>>Sub x_OnConnect
>>    MsgBox "you succeeded"
>>End Sub

>>Regards,
>>Captain Cerebrum
>>Innovative stuff for IE4 and HTML Help authoring
>>http://www.meadroid.com/wpm/
>>FREE ScriptX: Dynamic Event Binding, Printing
>>http://www.meadroid.com/scriptx


>>Suppose I have an ActiveX object firing an event "OnConnect". How can I
>>catch that Event with VBScript in the Script Control?

>>Something like this ??

>>Dim x
>>x = CreateObject("MyActiveX")



Mon, 19 Mar 2001 03:00:00 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. event handling in Script Control

2. Handling Control Array Events?

3. Handling User Defined Events from ActiveX Controls

4. How to handle ActiveX control event in Jscript?

5. How to handle activex events in a script

6. Dynamic event handling using scripting languages

7. Handle Events from script using ScriptControl

8. Could HTML Events be Handled from script file ?

9. Run .NET script code and handle .NET events from inside IE with VsaControl

10. Java Script - Handling Control Arrays

11. Script Control Error Handling - Annoying Debug Message

12. Determining the control handle for the currently active control

 

 
Powered by phpBB® Forum Software