Type Variables vs Class Modules

I have used TYPE many times. It is sort of a compromise between a bunch of isolated variables and a more formal Class object, the main difference being that things declared via TYPE have fields but no special properties. They also have no inherent methods. The down side is that as a complex structure, you can't store them in a recordset in the TYPE form. But you COULD store the individual fields within the TYPE as fields in a recordset. Note that this differs from VBA file usage, where you can create a formatted file consisting of TYPE blocks.
 
They are great for modeling data structures and I use them when I can, but the problem is that I can't store them in a dictionary or collection. In these cases, I usually end up using a class. Since UDTs are a value type, I suppose that they are faster than class objects? In other languages this is the case, but I don't know about VBA.
 
I like them with functions where you do something like find a record in a recordset and you want to return a couple pieces of information instead of just one. So instead of doing a bunch of dlookups you can have the function return a bunch of data about that record.
 
Here is an example to a bizarre problem
 
Here is an example to a bizarre problem
I followed that thread. Impressive solution you offered.
 

Users who are viewing this thread

Back
Top Bottom