Click to See Complete Forum and Search --> : Error creating an object


smakadia
July 10th, 2001, 09:02 AM
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.

CodeHacker
July 10th, 2001, 10:13 AM
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

smakadia
July 10th, 2001, 10:23 AM
You can't use the keyword new in the same line as withevents. Causes a compile error.