|
-
Sep 1st, 2000, 04:16 AM
#1
Thread Starter
Hyperactive Member
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.)??
-
Sep 1st, 2000, 04:58 AM
#2
Declare the object with the WithEvents keyword.
-
Sep 1st, 2000, 07:40 AM
#3
Guru
-
Sep 1st, 2000, 05:23 PM
#4
Thread Starter
Hyperactive Member
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
-
Sep 1st, 2000, 05:30 PM
#5
Set a reference to Microsoft Excel Object Library and declare an object with the WithEvents keyword.
Code:
Private WithEvents xl As Excel.Application
Add the above line to the general declaration of a form or a class module.
Click down the Object combo box in the code window and choose xl. And there you go...
-
Sep 6th, 2000, 03:07 AM
#6
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.
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
But why do you want to remove the reference?
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|