• Data used with random access files is most often stored in user-defined
variables. These data types group variables of different types into one assembly
with a single, user-defined type associated with the group. Such types significantly
simplify the use of random access files.
• The Visual Basic keyword Type signals the beginning of a user-defined
type declaration and the words End Type signal the end. An example best illustrates
establishing a user-defined variable. Say we want to use a variable that describes
people by their name, their city, their height, and their weight. We would define
a variable of Type Person as follows:
Type Person
Name As String
City As String
Height As Integer
Weight As Integer
End Type
These variable declarations go in the same code areas as normal variable declarations,
depending on desired scope. At this point, we have not reserved any storage for
the data. We have simply described to Visual Basic the layout of the data.
• To create variables with this newly defined type, we employ the usual
Dim statement. For our Person example, we would use:
Dim Lou As Person
Dim John As Person
Dim Mary As Person
And now, we have three variables, each containing all the components
of the variable type Person. To refer to a single component within a user-defined
type, we use the dot-notation:
VarName.Component
As an example, to obtain Lou’s Age, we use:
Dim AgeValue as Integer
.
.
AgeValue = Lou.Age
Note the similarity to dot-notation we’ve been using to set properties
of various Visual Basic tools.