- Declaring a structure
- Using an array of structures
How to use an array of structures?
An array of structures is an Array variable. Each array element is a Structure. For example, an array of structures can be used: - to store an array of order lines.
- to store a list of contacts.
To declare an Array of Structures variable, you must - Declare the structure.
- Declare an array of the structure previously declared.
The syntax is as follows
MyStructure is Structure Member1 is <type of variable> Member2 is <type of variable> ... END
MyArray is array of MyStructure
For example:
stOrderLine is Structure LineNum is int ProductRef is string Qty is int UnitPrice is currency END arrOrdLines is array of stOrderLine
Using an array of structures To use an array of structures, you must: - Declare an Array of the structure previously declared.
- Declare a simple variable representing an element of the type of the structure.
- Initialize the members included in this simple variable.
- Add this simple variable to the array.
For example:
stOrderLine is Structure LineNum is int ProductRef is string Qty is int UnitPrice is currency END AnOrdLine is stOrderLine arrOrdLines is array of stOrderLine // Fill the array AnOrdLine.LineNum = 1 AnOrdLine.ProductRef = "Ref001" AnOrdLine.Qty = 5 AnOrdLine.UnitPrice = 100.0 ArrayAdd(arrOrdLines, AnOrdLine) AnOrdLine.LineNum = 2 AnOrdLine.ProductRef = "Ref005" AnOrdLine.Qty = 1 AnOrdLine.UnitPrice = 2100.0 ArrayAdd(arrOrdLines, AnOrdLine) AnOrdLine.LineNum = 3 AnOrdLine.ProductRef = "Ref019" AnOrdLine.Qty = 16 AnOrdLine.UnitPrice = 22.0 ArrayAdd(arrOrdLines, AnOrdLine) // Read the array again: method 1 FOR EACH ELEMENT OrdLine OF arrOrdLines Trace(OrdLine.ProductRef, OrdLine.Qty, OrdLine.Qty * OrdLine.UnitPrice) END // Read the array again: method 2 FOR nSub =1 TO arrOrdLines.Count Trace(OrdLine[nSub].ProductRef, OrdLine[nSub].Qty, OrdLine[nSub].Qty * OrdLine[nSub].UnitPrice) END
Remarks The structures and the arrays of structures can be declared: - in the project code (structure global to the entire project).
- in the code of a window or page (structure global to the window or page).
- in any process or event (structure local to the process or event).
This page is also available for…
|
|
|
|