Defining User-Defined Types

The definition of a User-Defined Type begins with the reserved word TYPE and ends with the keywords END TYPE. In between, you define the names and data typesof the member elements (fields) that are to be part of the new Type. For example:

TYPE StudentRecord

LastName AS STRING * 20 ' A 20-character string

FirstName AS STRING * 15 ' A 15-character string

IDnum AS LONG ' Student ID, a Long-integer

Contact AS STRING * 30 ' Emergency contact person

ContactPhone AS STRING * 14 ' Their phone number

ContactRel AS STRING * 8 ' Relationship to student.

AverageGrade AS SINGLE ' Single-precision % grade

END TYPE

Remember that the definition of a User-Defined Type does not set aside memory for storing data of that Type. Rather, it defines a template for the new Type StudentRecord. Then when the compiler encounters a statement declaring (or creating) a variable of the new Type, it will "know" how many bytes of storage to set aside for the variable. In order to use this new Type, you must declare variables of that Type with the DIM statement:

DIM Student AS StudentRecord

See Also

User-Defined Types (UDTs)

Accessing the fields of a User-Defined Type

Nesting User-Defined Types

Arrays within User-Defined Types

Using arrays of User-Defined Types

Using User-Defined Types with procedures

Storage requirements and restrictions

Unions