![]() |
Program design question...
Hi all,
Just wondering what the recommended design approach is with VBA in regards to classes versus modules. I come from an OO background and am used to writing functionality within Classes or if I really bend the rules, static methods. With VBA there seems to be two choices - create a Class that contains the functionality I desire or create a Module that performs the same functionality that can be called "statically" without instantiating. What is the recommended approach within VBA..? For instance, I am writing an automated commentary tool that compares derived values against various thresholds and then uses these pass/ fail conditions to select predefined pieces of text. These are assembled in a hierarchy to produce a textual summary of the data. I can see two ways of doing this in VBA, 1) Create a type that stores these derived values as they are calculated and then pass the populated type to a module that extracts the values one by one and performs the necessary logic to create the commentary, 2) Create a class, instantiate the class and set each property with the derived values then call MyClass.Generate() which triggers the class to perform the same logic to return the commentary. Both approaches seem correct in the VBA world so I was wondering which is more correct. Thanks in advance. Lyndon. |
Program design question...
I don't believe either approach is "more correct." Go with what works
best for you. Mark Lincoln On Jun 25, 11:25 am, Lyndon wrote: Hi all, Just wondering what the recommended design approach is with VBA in regards to classes versus modules. I come from an OO background and am used to writing functionality within Classes or if I really bend the rules, static methods. With VBA there seems to be two choices - create a Class that contains the functionality I desire or create a Module that performs the same functionality that can be called "statically" without instantiating. What is the recommended approach within VBA..? For instance, I am writing an automated commentary tool that compares derived values against various thresholds and then uses these pass/ fail conditions to select predefined pieces of text. These are assembled in a hierarchy to produce a textual summary of the data. I can see two ways of doing this in VBA, 1) Create a type that stores these derived values as they are calculated and then pass the populated type to a module that extracts the values one by one and performs the necessary logic to create the commentary, 2) Create a class, instantiate the class and set each property with the derived values then call MyClass.Generate() which triggers the class to perform the same logic to return the commentary. Both approaches seem correct in the VBA world so I was wondering which is more correct. Thanks in advance. Lyndon. |
All times are GMT +1. The time now is 05:39 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com