PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
An array of structures is an Array variable. Each array element is a Structure. For example:
  • storing an array of order lines.
  • storing a list of contacts.
Declaring a structure
To de déclare an Array of Structures variable, you must
  1. Declare the structure.
  2. Declare an array variable (same type as the structure).
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 variable (same type as the structure).
  2. Declare a simple variable representing an element (same type as the structure).
  3. Initialize the members taking part in this simple variable.
  4. Add this simple variable into 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..Occurrence
Trace(OrdLine[nSub].ProductRef, OrdLine[nSub].Qty, OrdLine[nSub].Qty * OrdLine[nSub].UnitPrice)

END
Notes
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 (structure local to the process).
Minimum version required
  • Version 22
This page is also available for…
Comments
Click [Add] to post a comment