CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Location
    CT
    Posts
    75

    Error creating an object

    Hi. I am a VC++ developer. This is the first time I'm using VB. I have a COM component which is not a control, that fires an event. In VB I want to catch this event so I created an object using WithEvents. I then do a new on the object but it's here that it complains when I run the app.
    The code follows:

    option Explicit
    private withevents mEvent as MsgGrabber

    private Sub Form_Load()
    set mEvent = new MsgGrabber
    End Sub

    private Sub mEvent_MessageRetreived(byval bstr as string)
    MsgBox "This is the string: " + bstr
    End Sub

    private Sub Send_Click()
    mEvent.SendMessage ("Client string")
    End Sub



    MsgGrabber is my COM interface's implementation. The compiler complains on the Set statement. The error I get is:
    Automation Error
    The specified module could not be found.

    Any help would be appreciated.


  2. #2
    Join Date
    Apr 2001
    Posts
    90

    Re: Error creating an object

    I think you want to change your declaration to


    private withevents mEvent as new MsgGrabber




    then drop the set statement. Then your sendmessage should work OK. Also make sure your COM object is registered of course. To do it the way you have it take a look at GetObject. Sometimes you don't want to use new in your declaration if there's a chance that you won't actually need the object in the life of the app.

    Also, place a...


    set mEvent = nothing




    in your form unload

    CodeHacker
    Rate me if it helped, Thanks

  3. #3
    Join Date
    May 1999
    Location
    CT
    Posts
    75

    Re: Error creating an object

    You can't use the keyword new in the same line as withevents. Causes a compile error.


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

Featured