Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2004, 11:38 PM
Registered User
 
Join Date: Jan 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nhdw
Default Events Question

Quick Question regarding events in VB6...

I originally created a class (with no events), and the procedure in my original program had no problem seeing the members of the class after it instantiated an object derived from that class.

Once events were added, the only way I could get the original program to "Capture"/Sink/Consume (not sure if they're all synnomous or not) the events that I added was to change the declaration of the object from "Private MyObj as New ClassICreated" to "Private WithEvents MyObj as ClassICreated" (since WithEvents and New don't mix for some reason)...

Now whenever I try to call a method or property from ClassICreated, I get "Method or Data Member Not Found" ...

I already tried "Set MyObj as New ClassICreated" in my code, but still no go...

Maybe my understanding of events is somewhat flawed.. Why can't you use "WithEvents" and "New" on the same declaration line? As long as I use "New" on the declaration line, the Methods/Data Members are seen, but the events are not. If I use "WithEvents", I get "Method or Data Member Not Found" compile-time errors.

Any help would be greatly appreciated.


 
Old February 23rd, 2004, 11:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ok.. first of all.. why not use set xxx as NEW xxx

form my point of view (and all that i read), if you do something like that you are adding overhead to your code, and can be very bad if you use that object a lot of times in your code...
every time you reference that object, VB auto adds control code to see if that is the first time you reference it, and if it true then it load the class..

you will have something like this

if xxx is nothing then
   set xxx = new xxx

but automatic by VB...

i think your error is not starting the object.. maybe you miss the set xxx = new xxx at the start of your code??

Gonzalo Bianchi
 
Old February 23rd, 2004, 04:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There are some limitations on the use of WithEvents. For example, you cannot use an generic Object variable. I think this is the reason you cannot use it with New: when the compiler creates a New object (declared as New) for you, it does not know what type of object it is.
Regarding your specific problem, you did not mentioned if the class is in the same or in a separate project (that makes a difference)

Marco





Similar Threads
Thread Thread Starter Forum Replies Last Post
Events are not firing msrnivas .NET Web Services 14 April 21st, 2008 06:37 AM
Events bschleusner C# 2005 2 February 26th, 2007 05:25 AM
Events in User Controls question Aaron Edwards ASP.NET 1.0 and 1.1 Basics 1 December 6th, 2005 02:59 PM
VS.net Question : Protected with Events shahchi1 VS.NET 2002/2003 2 May 23rd, 2004 08:06 AM
help with Events egiblock JSP Basics 0 October 6th, 2003 11:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.