ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / How to proceed? / Programming
  • Declaring a structure
  • Using an array of structures
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
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.
Declaring a structure
To declare an Array of Structures variable, you must
  1. Declare the structure.
  2. 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:
  1. Declare an Array of the structure previously declared.
  2. Declare a simple variable representing an element of the type of the structure.
  3. Initialize the members included in this simple variable.
  4. 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).
Minimum version required
  • Version 22
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 10/27/2022

Send a report | Local help