[AccessD] Just curious

John W. Colby jcolby at colbyconsulting.com
Sun Feb 16 22:23:00 CST 2003


lol.  Guess I should proofread my stuff eh.  If the claim is an injury it
cannot be an illness and V.V.

Sorry bout that.

John W. Colby
Colby Consulting
www.ColbyConsulting.com

 -----Original Message-----
From: 	accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com] 
Sent:	Sunday, February 16, 2003 11:13 PM
To:	accessd at databaseadvisors.com
Subject:	RE: [AccessD] Just curious

Bryan,

>I can use classes. I can use WithEvents. I just can't seem to use them
together.

You can't use Withevents without using classes.  Maybe your problem is
trying to use Withevents in a module?  ;-)

All that Withevents is doing is moving the event sink for some event for
some object into a custom class.  That is why I say it is a very simple
concept and very easy to implement.

Why would you do this?  Let me give you a concrete, real life example.  In
an insurance app I wrote, the client had 5 check buttons that defined a
system.  the check buttons were bound to 5 fields in a table.  The fields
had a set of rules that the insurance company set up and had to be enforced.
If a claim was an injury, it could not be an injury.  If it was a pregnancy
it was an illness, not an injury.  etc.

I set up a custom class to implement this set of rules (there were more
rules than that).  I then fed pointers to the actual check boxes into the
class and saved them to local (to the class) check box variables dimmed
WithEvents.  Dimming an object Withevents tells the compiler that the object
(a check box in this case) can source events (OnClick in this case) and that
we expect to sink (handle) the event in this class.  

Thus by dimming 5 check box variables, Withevents, passing in references to
all of these checkboxes from the form, and setting my local variables equal
to the passed in controls, I set up the form to sink the events for these
checkboxes.  The last piece of the puzzle is to actually build the event
sink (sub) in the class which I did.  Now, whenever the user clicked on the
check box, the code control was passed directly to my class.  Inside my
OnClick subs (5 of them, one for each check box) I checked what other check
boxes were set, set the other check boxes necessary and cleared any check
boxes necessary.

In essence I now have a class that handles the click event for 5 check
boxes, can set and clear these check boxes, and uses that ability to
implement a complex set of rules for these 5 check boxes.

Why would I build a class to do this, rather than just doing it in the form
you ask.  The answer is simple, and actually there are two related answers.
First, I had several forms that displayed these records.  One was an initial
data entry form where some key person just put in new records, nothing else.
The other was a form where the whole company could view and modify these
records.  In both forms, the same rules had to be applied.  IOW, the check
boxes and the applicable rules were a "system".  By encapsulating it in a
class, I could build as many forms as I wanted and just instantiate the
class, passing in the check boxes.  

ALL processing was done internal to the class.  I can go change the rules in
the class and it changes for every form that uses the class.  Could this be
done without a class.  Sure, but it is uglier and requires pieces (the event
stubs and calls to code) to be placed in each form.  

Using a class, if you want to see every piece of the code applicable to that
system, just open the class and examine it.  OO programming is based on some
ideas, one of which is encapsulation.  Build a "box" that handles the whole
thing.  Using a class and Withevents allows me to encapsulate the whole
thing, including the event stubs that would otherwise be in each form.

John W. Colby
Colby Consulting
www.ColbyConsulting.com

-----Original Message-----
From: accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com]On Behalf Of Bryan Carbonnell
Sent: Wednesday, February 12, 2003 8:43 PM
To: accessd at databaseadvisors.com
Subject: RE: [AccessD] Just curious


On 12 Feb 2003 at 17:26, John W. Colby wrote:

> I started using classes hmmm... about 3 or 4  years ago now.  I
> started seeing the occasional cryptic message about WithEvents from
> this Russian Guy (Shamil) which caught my attention.  I went to his
> site and downloaded all of his demos, but had a bit of a rough time
> understanding the concept. Looking back, I don't really understand
> why.  It's really easy stuff but I did.  Tried it, went away, tried
> it, went away.  Finally one time it just clicked.  It clicked so well
> that I decided to completely rewrite my framework to be class /
> withevents driven.  Which I did.

What caused it to click? Just hammering at it time and time again?

I've tried understanding that Russian guy's stuff :-)) and it hurts my 
head. I can use classes. I can use WithEvents. I just can't seem to 
use them together.

Is it just a case of try to understand, then try again and again and 
again until the magic moment happens and it just finally clicks?

Maybe it's just too DEEP for me right now :-))

--
Bryan Carbonnell - carbonnb at sympatico.ca
Never test for a bug you don't know how to fix.


----------------------------------------------------
Is email taking over your day?  Manage your time with eMailBoss.  
Try it free!  http://www.eMailBoss.com

----------------------------------------------------
Is email taking over your day?  Manage your time with eMailBoss.  
Try it free!  http://www.eMailBoss.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 4288 bytes
Desc: not available
URL: <http://databaseadvisors.com/pipermail/accessd/attachments/20030216/468254bb/attachment-0002.bin>


More information about the AccessD mailing list