Type Variables vs Class Modules (1 Viewer)

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:50
Joined
Feb 28, 2001
Messages
27,001
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.
 

dataluver

New member
Local time
Today, 07:50
Joined
Feb 7, 2020
Messages
5
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.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:50
Joined
May 21, 2018
Messages
8,463
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.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 07:50
Joined
May 21, 2018
Messages
8,463
Here is an example to a bizarre problem
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 07:50
Joined
Apr 27, 2015
Messages
6,286
Here is an example to a bizarre problem
I followed that thread. Impressive solution you offered.
 

Users who are viewing this thread

Top Bottom