Bookshelf Home | Contents | Index | Search | PDF |
Siebel VB Language Reference > Siebel VB Language Reference >
Type Statement
This standard VB statement declares a user-defined type.
Syntax
Type userType
field1 As type1
field2 As type2
...
End Type
Argument Description userType The name of the user-defined type field1, field2 The names of fields in the user-defined type type1, type2 The data types of the respective fieldsReturns
Not applicable
Usage
The user-defined type declared by Type can be used in a Dim statement to declare a record variable. A user defined type is sometimes referred to as a record type or a structure type.
Field cannot be an array. However, arrays of records are allowed.
The Type statement is not valid inside a procedure definition. It must be placed in the (general) (declarations) section, shown in Figure 1. User defined Types cannot be passed to COM Object functions or subroutines.
To access the fields of a record, use syntax of the form:
recordName.fieldName
To access the fields of an array of records, use syntax of the form:
arrayName(index).fieldName
No memory is allocated when a type is defined. Memory is allocated when a variable of the user defined type is declared with a Dim statement. Declaring a variable of a user defined type is called instantiating, or declaring an instance of, the type.
Example
This example shows a Type and Dim statement for a record. You must define a record type before you can declare a record variable. The subroutine then references a field within the record.
Type Testrecord
Custno As Integer
Custname As String
End TypeSub Button_Click
Dim myrecord As Testrecord
Dim msgText As String
i:
myrecord.custname = "Chris Smith"
If myrecord.custname = "" then
Exit Sub
End If
End SubSee Also
Bookshelf Home | Contents | Index | Search | PDF |
Siebel VB Language Reference Published: 18 June 2003 |