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?
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?