Macros and the IBM CognosScript Language  7.5.0
IBM CognosScript Statements and Functions >

Type Statement

Description

Declares a user-defined type.

Syntax

Type userType

field1As type1

field2As type2

...

End Type

where:

is:

userType

A user-defined type.

field1 , field2

The name of a field in the user-defined type.

type1 , type2

A data type: Integer, Long, Single, Double, Currency, String, String*length, Variant, or another user-defined type.

Comments

The user-defined type declared by Type can then be used in the 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 of a procedure definition. To access the fields of a record, use notation of the form:

recordName.fieldName

To access the fields of an array of records, use notation of the form:

arrayName( index ).fieldName

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 Type
Sub main
   Dim myrecord As Testrecord
i: myrecord.custname=InputBox("Enter a customer name:")
   If myrecord.custname="" then
      Exit Sub
   End If
   answer=InputBox("Is the name: " & myrecord.custname_
      &" correct? (Y/N)")
   If answer="Y" or answer="y" then
      MsgBox "Thank you."
   Else
      MsgBox "Try again."
      Goto i   
   End If
End Sub

See Also

Deftype Statement

Dim Statement