User-Defined Data Types
E-Basic allows the user to define data types. A user-defined data type is declared using the Type statement, and the data items organized by the data type are listed within the Type statement. User-defined data types must be declared on the User tab of the User Script window; they cannot be declared on an In-Line object.
User-defined data types are very useful for organizing related data items of various types. For example, to draw and modify a grid in which some of the cells are drawn in color, it would be useful to keep track of an ID number for each cell, the color in which each cell is drawn, the location of the cell, and other possible information about each cell. The script below uses the Type statement to declare the CellInfo data type, organizing the data relevant to each cell in the grid.
|Type CellInfo ‘keep track of cell info|
|nID As Integer|
|nColorState As Integer||‘Is the cell a color or non-color nColor|
|As Long||‘Specific color used to draw the cell|
|nRow As Integer||‘Row in the grid where cell appears|
|nColumn As Integer||‘Column in the grid|
Within the Type declaration of the CellInfo data type, variables are declared to organize the information pertaining to each cell (i.e., the cell ID, color of the cell, row, column, etc.). Once the data type has been declared, the Dim command is used to declare a new instance of the type. For example, the script below declares the CurrentCell variable as an instance of the CellInfo type (i.e., a single cell in the grid).
|Dim CurrentCell As CellInfo|
If the CurrentCell variable declaration is made on the user tab of the Script window, after the CellInfo type definition, then the CurrentCell variable becomes a global variable. Alternatively, if the variable declaration is made on an InLine object, then it is participant to the scope rules in GENERAL: Variable Declaration and Initialization .
Like assigning values to object properties, the dot operator is used to assign values to the component variables of a user-defined type. Below, the CurrentCell variable is assigned values for the ID number, row, column, color state, and color components.
|'Define cell info|
|CurrentCell.nID = 12|
|CurrentCell.nRow = 2|
|CurrentCell.nColumn = 3|
|CurrentCell.nColorState = 1||'1 = color, 0 = white|
|CurrentCell.nColor = CColor("Blue")|
Recall that the assignment script can only occur on an InLine object; this script can NOT be placed on the User tab of the Script window.