Hi!
If I want to use eg. WinSock on formless application, I have to use CreateObject method.
But how can I tell what to do if an event occurs (DataArrival, ConnectionRequest, etc.)??
Printable View
Hi!
If I want to use eg. WinSock on formless application, I have to use CreateObject method.
But how can I tell what to do if an event occurs (DataArrival, ConnectionRequest, etc.)??
Declare the object with the WithEvents keyword.
This won't work with your winsock. :(
Use a winsock classmodule, I think it can be found somewhere on Planet Source Code. :rolleyes:
OK, so how can I catch the events on external objects, for example excel (have I to found Excel classmodule :)?); I did not mean only WinSock...
PS: Can you please tell me where is the WinSock classmodule?
Thanks,
John
Set a reference to Microsoft Excel Object Library and declare an object with the WithEvents keyword.
Add the above line to the general declaration of a form or a class module.Code:Private WithEvents xl As Excel.Application
Click down the Object combo box in the code window and choose xl. And there you go...
Just as parksie said; you can't use WithEvents in a normal module. But you can use it in a Form module if you like.
If you remove the reference VB can't compile the application because it doesn't know what Excel.Application is then.
You can, however, declare it as a general object but not if you want to use events.
But why do you want to remove the reference?Code:Private xl As Object 'this works without having any reference
Private WithEvents xl As Object 'you can NOT use WithEvents with an Object object
Even if the end user doesn't have Excel you won't get any errors before you try to create the object.
But that error is trappable if you use On Error code.