Need some advice on a simple Class

on your demo, the Ribbon is showing, will it be shown on the Actual db?
if it is, you also need to code when users click the Filter (Asc/Desc) or click the Remove filter so that your label will
respond to the change.
Good point, but at this point, my sole aim is to learn how to pass different count of the same type of controls to a class and make them all behave the same.

If I take this to our DB, we would be safe, because our ribbon is set to startFromScratch='true' and we don't have Sort options in any of its 9 tabs.
All our continuous forms, rely on two public functions that add this sort functionality. But getting familiar with this method and understanding how it works, I'm tempted to add it.

Thanks.
 
> But 3 classes for a simple task like this is too much.
yes it is overkill.
In my opinion, the number of classes doesn't say much about overkill.
A few more classes can certainly achieve a better separation of responsibilities and if a few generally usable classes are then created, I even see this as an advantage.

Attached is my suggestion for the task in #1
 

Attachments

i also will stick with my 3 class
 

Attachments

Good point, but at this point, my sole aim is to learn how to pass different count of the same type of controls to a class and make them all behave the same
If you look at these three approaches they are all slightly different versions of the same general techniques. Each version is slightly more encapsulated and as
@Josef P. states this is good.
A few more classes can certainly achieve a better separation of responsibilities and if a few generally usable classes are then created, I even see this as an advantage.
1. All three approaches have a composition class that holds the labels and basically extends the properties of that label and captures the label events. In other languages that really supported OOP you would not do this. You would create a class (in my case SortableLabel) that inherits a Label and truly extends the methods and properties of a label. However VBA does not support inheritance so you have to build a composite class that has a label as a class property and uses with events.
2. All approaches then have a class that holds the instances of the class. I call this a collection class.
3. All approaches trap the label event of the instances held in the collection and then call a procedure that raises a common event that can be trapped somewhere else.

If you look at what @arnelgp did this is a more fundamentally correct version of what I did. He created a Listener Class / Notifier class where the instances call an procedure that raises the event then you only have to listen to a single event raised by the notifier / listener class. As I said my approach seems a little quirky in that the collection class is also the notifier. This means the label instances have to know about their own collection as they are created. It works but not fundamentally correct IMO.

So bottom line, it is some modified version of this.
1. Create your "label" class that brings in the label using withevents to trap its events. Create all the additional properties. This class knows nothing of other custom labels and does not do any of the processing of the filtering and property setting.
2. Create some kind of a collection class to hold your custom labels.
3. Create some kind of listener that your custom labels call a method to then raise a single custom method.
In my case I did not really raise another event, but did the processing directly in the collection class.
4. Have the collection class do the processing.
 
How to add a new event to your class? (For now the file in #15)
Not sure if you are aware of this. If not this is a huge time saver.

When you add a class variable with Events you then can choose from the drop down to add the events just like any form or control object.
So m_label is added with events as a label object. It then appears in the pulldown.
WithEvents.jpg


Once you select from the left pulldown you can add the events from the right.

WithEvents2.jpg


More important this works with classes that raise custom events like my SortableLabels class

WithEvents3.jpg
 

Users who are viewing this thread

Back
Top Bottom