type ... is Declaration

Action

Declares an alias data type.

Note: Data type declarations must appear outside of any function.

Syntax

[scope] type type-name is data-type [, data-type]...
Variable Description
scope Optional: Either public (the default) or private. Private declarations are available only in the file in which they occur. Public declarations can be accessed from other files by means of a use statement.
type-name An identifier that names the type being declared.
data-type Any legal data type. If you specify only one data-type, variables of type-name can hold only data of that data type. If you specify multiple type names, objects with the new data type can hold data of any of the types you specify. This is called overloading and is described below.

Notes

  • Declare aliases to create new data types that are specific to the needs of your scripts, or the application you are testing. An alias can simply be a new name for an existing type, or can be used to declare variables that can be assigned values of more than one type. This is called overloading.

  • In the following example, a variable with type ManyItems can hold data with either of the user-defined types MyEnumType or MyRecordType:
    type ManyItems is MyEnumType, MyRecordType
  • Overloading is useful when you want variables or function parameters to hold data of multiple types, like a string from a dialog box or its index value, which is an INTEGER. You could use type ANYTYPE for this purpose, but declaring an overloaded alias makes your code more robust.

  • To test the type of the data that an overloaded variable actually holds, and then perform different operations based on the result, use a switch statement in combination with the TypeOf function:
    [ ] type MyType is INTEGER, STRING
    [-] MyType ShiftyVar
    	[ ] 
    [-] switch (TypeOf (ShiftyVar))
    	[-] case INTEGER:  
    		[ ] // If the value TypeOf returns is INTEGER 
    		[ ] // do whatever... 
    	[-] case STRING: 
    		[ ] // if value is string... 
    		[ ] // do something else...

Examples

[ ] type int is INTEGER // For people accustomed to C
[ ] type FILE is LIST OF STRING
[ ] type MATRIX is ARRAY [4][4] OF NUMBER
[ ] type MATRIX_LIST is LIST OF MATRIX
[-] public type ITEM is INTEGER, STRING
	[ ] //holds integers or strings