Wrapping controls WithEvents in classes

There is even a song to go with it. But I realize now I typed the quote wrong and should read "I've got mine"

And yes as @NauticalGent pointed out, super creepy and disturbing.
I like it better the way it is now. It expresses a certain je ne sais quoi.
 
I like it better the way it is now. It expresses a certain je ne sais quoi.
Actually I did have it correct, as @cheekybuddha said, it does say that quote in the last line of the song. Not that there was any "je ne sais quoi" thought put to this, I just copied something from the internet (top ten famous quotes from..)
I used to have Les Grossman from Tropic Thunder as my avatar until several people really thought it was me and said it was not a very flattering picture. So I went with this assuming no one really would really think it was me. Bizarrely that picture really does look like my dad without the big hair. Sorry for derailing this thread with my avatar discussion.
 
However all the form has at this time is the controls, no code? so that is not going to work?
You then ask to open ClsFrm and add a Close event and amend the Init event.
The first thing that you should notice is that the events of the class fire, displaying the
“Initialize” debug statement. Remember I said that unlike regular modules, classes have
two events that fire when they instantiate. We have created sinks in the class module to
sink these events and so the debug statement will execute when we instantiate the class.
 Close the form
Thanks for the book @jwcolby54, enjoying it. Obv's in the interest of constructive feedback I'd agree with @Gasman here. Up to p28 & as @Gasman mentioned p27 says that we are able to step through & fire the after_update events; which of course we haven't hooked up the main frm yet... & are not able to do this.

Again thanks for the book.
 
Thanks for the book @jwcolby54, enjoying it. Obv's in the interest of constructive feedback I'd agree with @Gasman here. Up to p28 & as @Gasman mentioned p27 says that we are able to step through & fire the after_update events; which of course we haven't hooked up the main frm yet... & are not able to do this.

Again thanks for the book.
@dalski And thank you for reading and commenting on it. I will go look at page 28 and fix it.

As you may have discovered, the book PDF is live out on GitHub.

But can you cut and past a small bit of the text into here so I can search for and find it?

I have switched from .odt to .Fodt, which is a "straight xml format" for the book I am writing in LibreEdit. I have no idea whether it may cause minor changes in the formatting or whatever.
 
Last edited:
Tony,
So why not use the AfterUpdate event of the control on the date picker form to calculate the age and update what is needed?
 
You could just set the ControlSource of txtAge to:

=IIf(IsDate([txtBirthDate]), AgeFromDOB([txtBirthDate]), Null)

(where AgeFromDOB() is your function that calculates age)
 
@dalski cut and past a small bit of the text...

Thanks @jwcolby54, I was basing my experience on the most recent .pdf on this post. I see a lot of references to GitHub but have not found a link to it. My humble feedback is the second e.g. insinuates that the code will run, & is detailed in it's step by step process. But there are no references to hooking up the frmDemoCtls to the clsFrm.
Thanks again for the book. Stating the obvious any fool can critique a book, very few can write one. Merely trying to help (albeit a little):

p29 "You can prove that to yourself by deleting this text in some property of some form or control in an existing project, cause that event to fire, and notice that the code no longer runs in your code behind form. Put that text string back and notice that the event code now runs in your code behind form"
The code cannot run, it is not hooked up to external form yet. It gives the user the impression they have not set-up correctly with their code not running. When they have followed each step.

p31 " Save the class and open the form. The first thing that you should notice is that the events of the class fire, displaying the “Initialize” debug statement."

p33 - For Each ctl in mfrm.Controls
1749379523281.png
 
Last edited:
Thanks @jwcolby54, I was basing my experience on the most recent .pdf on this post. I see a lot of references to GitHub but have not found a link to it. My humble feedback is the second e.g. insinuates that the code will run, & is detailed in it's step by step process. But there are no references to hooking up the frmDemoCtls to the clsFrm.
Thanks again for the book. Stating the obvious any fool can critique a book, very few can write one. Merely trying to help (albeit a little):

p29 "You can prove that to yourself by deleting this text in some property of some form or control in an existing project, cause that event to fire, and notice that the code no longer runs in your code behind form. Put that text string back and notice that the event code now runs in your code behind form"
The code cannot run, it is not hooked up to external form yet. It gives the user the impression they have not set-up correctly with their code not running. When they have followed each step.

p31 " Save the class and open the form. The first thing that you should notice is that the events of the class fire, displaying the “Initialize” debug statement."

p33 - For Each ctl in mfrm.Controls
View attachment 120164
@dalski the actual live PDF can be found here:

EventDrivenProgrammingInVBA.pdf

And yes, I have been accused of writing like a drunken fireman spraying water from a firehose. Please do download that and please store a reference to the book somewhere.

I have a saved page reference in my browser, in my Colby Consulting folder of page references, which points out to my blog on this subject.

This is my old blog, directly. With a sidebar. Pointing to the book blog post directly

John Colby's blogspot
 
Ok, for those who could be interested, the link is actually https://jwcolby.blogspot.com/2025/05/the-book-event-driven-programming-in.html
This is a better link to all the sections.

Now John, I have a question. Please excuse my likely stupidness, but on Page 18 we are creating basInitClass and basInitClasses ?
It appears that I create basInitClass and the save it again as basInitClasses?, which I cannot do, unless I copy all the code to a new module.
Looking at your demo db, there is no basInitClass?

Could you elaborate on this please?
@Gasman I know you are done :cry: but the latest version has chapters now. If you have any comments on the new format I'd be all ears.
 
I'm going to revisit some of my old classes too.
I must say I'm having a ball playing around with the controls collection.

I re-wrote my Date picker class using the controls collection for the 42 command buttons for the dates.
So much less code than before. It's also much easier to set the different properties and methods of the controls. For instance hiding controls that fall outside the displayed month and highlighting special dates. I even added a procedure that gets all the common U.S. holidays ( all code, no holiday table) and highlights the corresponding control for the holiday. Hovering over it uses the controltip text to show the holiday name or whatever text was passed in.

It's gonna be fun applying all this to my calendar class.
 

Users who are viewing this thread

Back
Top Bottom