General questions about class modules

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
Hello all! I do not have a specific issue that I am having. Instead, I am seeking advice on better class module coding. So here goes!

1) I hate clutter. I have chosen not to create functions in a class module. Instead, I put what would have been the function in a Let Property statement. Are there any advantages or disadvantages to doing this?

2) The Get Property always triggers its Let Property. Is there a way to prevent this from happening? I feel like this is unnecessary execution of code. For example, the Let Property statement for a property called Is_Handsome would be something like pIs_Handsome = True and the Get Property statement would be something like Is_Handsome = pIs_Handsome (where pIs_Handsome is a module level boolean variable). I realize that I can put some code at the beginning of the Let Property statement to exit the property if certain conditions are met. I would rather know if there is a way to prevent the Let Property statement from triggering ONLY when the Get Property statement is being set. It just seems redundant!!

3) I've got some properties that are read-only. For example, I have a class called US_States. I have an enumeration where each state is given a value. So the US_States object is eventually assigned one of the values in the enumeration. One of the properties of this class is Abbreviation. So the Get statement is basically a Select Case statement that evaluates the enumeration value that was set and returns a string for the abbreviation. I hate how messy it looks having a line of code for each state (especially since every property for this class has the same sort of Select Case scenario). I realize I could create a variable that contains an array, but it is difficult to look at an array and know which value goes to what. I don't have the option of creating a table using a worksheet. Any suggestions on how else you might tackle this?

4) Which do you think is better -- class modules or data types? Why?

5) Do you have any general words of wisdom on the use of class modules that may help me be as efficient as possible and avoid any pitfalls that you may have encountered?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top