The main concepts for programming the memory Table controls are as follows.
Several WLanguage functions allow you to manage this type of control by programming. Do not hesitate to see the documentation about these functions.
Initializing a memory Table control
The creation of a row in a Table control is not automatically performed. It must be explicitly requested via a call to:
Note: if the cascading input is not selected:
- A Table control contains no row when it is created: TABLE_MyTable..Count=0.
In this case, no input is allowed and ..Empty is set to True. - To automatically insert a row if the Table control is empty, the following command lines must be used in the initialization process of the Table control:
IF TABLE_MyTable..Empty = True THEN TABLE_MyTable.Add()
Adding rows into a memory Table control
Adding rows into a memory Table control is performed:
Managing calculated columns
The calculation formula of a calculated column must be described in the event "Displaying a table row" of a Table control. For example:
// COL_PBT: calculated column
// COL_UPBT and COL_QTY: columns linked to memory zones
COL_PBT = COL_UPBT * COL_QTY
Modifying a row or a column
The content of a Table control's rows or columns can be modified:
- by the user, by performing an input in the columns. The modifications are automatically stored in the Table control with no additional programming. ..Modified is set to True.
- by programming:
- with <Table>.Modify to modify the content of the current row or the content of a given row.
For example:
TABLE_CUSTOMER.Modify("MOORE" + TAB + "Vince" + TAB + "Miami")
Note: you can also use the name of the Table control directly:
// Modify the current row
TABLE_CUSTOMER = "MOORE" + TAB +"Vince" + TAB + "Miami"
// Modify row 3
TABLE_DAY.Modify("Wednesday" + TAB + "Off", 3)
- by specifying the column name (like for an edit control) to modify the column content. To modify a column of a specific row, the row number must be specified (subscript).
For example:
COL_NAME[Subscript] = EDT_CustomerName
To modify a column of the current row, there is no need to specify the subscript. For example:
COL_NAME = EDT_CustomerName
..Modified is set to False (it is set to True when an input is performed in the Table control).
// Entry process in the COL_QTY column
// COL_QTY cannot be entered,
// if COL_PRODUCT is not entered
IF NoSpace(COL_PRODUCT) = "" THEN
Error("The Product column must be entered first")
ReturnToCapture(COL_PRODUCT)
END
Operations on the rows and cells
Deleting a row
The deletion of a row must be explicitly requested by
<Table>.Delete. The following syntax is used:
TableDelete(<Table control>[, <Subscript>])
If the subscript is specified,
<Table>.Delete deletes the row corresponding to the subscript. Otherwise, the current row is deleted. For example:
The deletion of a Table control row also deletes all the values of the columns for this row.
A row can be selected by
<Table>.SelectPlus.
The following syntax is used:
<Table control>.SelectPlus([<ISubscript>])
Retrieving the row content or the cell content
The content of a memory Table control can be retrieved:
- for the entire row.
- cell by cell.
Value of a cell in the current row
To retrieve the value of a column (or cell) for the current row, the syntax is the same as for a simple edit control.
Example:
// COL_QTY is a column of the Table control
IF COL_QTY < 10 THEN
Info("Insufficient quantity")
END
Value of a cell in a specific row
To retrieve the value of a column not found on the current row, the row subscript must be specified.
<Value> = <Column name>[<Subscript>]
For example:
// Add the total price before tax (PBT) for all the order lines
TotalPrice = 0
FOR Subscript = 1 _TO_ TABLE_ORDERS..Occurrence
TotalPrice = TotalPrice + COL_PBT[Subscript]
END
Content of current row
To retrieve the content of the current row, use the following syntax:
<Value> = <Table control>
Content of specific row
To retrieve the content of the row whose subscript is <Subscript>, use the following syntax:
<Value> = <Table control>[<Subscript>]
Note: The subscript of the current row is returned by
<Table>.Select.
For example:
// Retrieve row #10 in the TABLE_CUSTOMER control
CurrentRow = TABLE_CUSTOMER[10]
// Name of selected customer
CustomerName = COL_NAME[TABLE_CUSTOMER.Select()]
// Retrieve the current row in the TABLE_CUSTOMER control
CurrentRow = TABLE_CUSTOMER