A Structure is a data type that contains one or more fields. These fields can be of different data types themselves. In ATEasy, you first create a Type of data type "Struct". Once it is declared, you can use it in code. For instance, you declare a Type as "Struct" with the name "programmer", and then define two fields in that Structure (one field named "FirstName" as String and the other field named "Age" as Short).
Types
===========
programmer: Struct
{
sFirstName: String
nAge: Short
}
Once a structure is defined, you can declare a variable of that structure, such as "programmerNew", where "programmer" is the prefix and "New" is the main part of the variable name:
programmerNew: programmer
In procedure code, you can assign values to the structure's components:
programmerNew.sFirstName="George"
programmerNew.nAge=45
A Structure can contain fields of any type, including an array or another Structure.
The fields of a struct can also have a struct type as a field. In the following example, the struct Class contains another struct Person:
Struct: Person
aName: String
Id: Long
Struct: Class
CourseName: String
Department: String
CourseNum: Short
Instructor: Person
nStudents: Short
aStudent: Person[40]
We define a history class:
clsHistory: Class
The name of the last student in the history class would be:
clsHistory.aStudent[clsHistory.nStudents-1].aName
Structure have a fixed size to accommodate their fields, you can use the SizeOf operator to determine the structure width. Structure fields that are array cannot be Redim, you can use a Variant field to store arrays, if you need to change the array dimension inside a structure field.
A structure variable can be assigned to a Variant data type and vise versa. When assigning a structure to a variant, an array will be created and store in the Variant, each array element represents a field. See Struct/Variant DataConversion for more information,