Results 1 to 6 of 6

Thread: How can I catch events from code-object?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    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.)??

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Declare the object with the WithEvents keyword.

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Cool Blah, not really

    This won't work with your winsock.
    Use a winsock classmodule, I think it can be found somewhere on Planet Source Code.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    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

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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...

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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
  •  



Click Here to Expand Forum to Full Width