User-defined types
User-defined types are aggregates of other types. Here’s a type:
Type TChunk
Title As String
Count As Integer
End Type
And here’s a variable that uses it:
Dim chunk As TChunk
chunk.Title = “Thick and Chunky”
chunk.Count = 6
As with the Integer variable, the UDT variable contains the instance. The name chunk refers to an instance containing the String Thick and Chunky and the Integer 6. (The string characters aren’t really an instance, but don’t confuse me with facts.) Unlike intrinsic types, UDTs have only two standard operations: assignment and member access.
Assignment works only on UDTs of the same type:
anotherchunk = chunk
Member access lets you do additional operations on the fields of a UDT variable:
c = chunk.Count
The other operations allowed on the fields are those supported by the field type. For example, Integer type supports assignment, so chunk.Count supports assignment. You can’t give a TChunk any additional operators or methods any more than you can give an Integer more operations. The only way to operate on a UDT is the functional way:
Sub SquareTChunk(chunk As TChunk)
chunk.Count = chunk.Count * chunk.Count
End Sub
I’m stating the obvious limitations of types here so that I can contrast them to the real subject of this section—classes.