PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • How to proceed?
  • Implementation
  • Position of calculation row
  • Customizing the calculation row
  • Deleting the custom calculation rows
  • Exporting the results of calculations
  • Export via the AAF (Automatic Application Features) of Table control
  • Export via the WLanguage functions
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
Overview
WINDEV allows you to easily insert automatic calculations into the columns found in the Table and TreeView Table controls.
From version 22, you also have the ability to perform automatic calculations in the columns found in the Table and TreeView Table controls. These calculations are performed by programming.
How to proceed?

Implementation

To implement a custom calculation in a column found in a Table or TreeView Table control, use TableFormulaAdd.
This function expects in parameter:
  • the name of the column taken into account for the calculation.
  • the caption of the row displaying the calculation in the table. If this caption does not exist, the row will be created. If this caption exists, the calculation will be displayed in the requested column.
  • the name of three procedures. These procedures are used to:
    • initialize the calculation,
    • perform a calculation for each table row,
    • perform the final calculation if necessary.
Example:
TableFormulaDeleteAll(TABLE_MyTable)
nRow is int
nRow = TableFormulaAdd(TABLE_MyTable.COL_Num, "Positive mean", ProcInit, ProcAdd, ProcEnd)
// Change the background color of the row for custom calculation
COL_Num[nRow]..BrushColor = LightRed

nCounter is int
INTERNAL PROCÉDURE ProcInit()
nCounter = 0
RESULT 0
END

INTERNAL PROCÉDURE ProcAdd(Accumulator, ColValue)
// Ignores the negative numbers or NULL
IF (ColValue <= 0) RESULT Accumulator
nCounter++
RESULT Accumulator + ColValue
END
INTERNAL PROCÉDURE ProcEnd(Accumulator)
IF nCounter = 0 THEN RESULT 0
// Calculate the mean
RESULT Accumulator/nCounter
END
Notes:
  • The custom calculation rows are automatically recalculated as soon as the content of the Table or TreeView Table control changes.
    Tip: The iteration procedure is called for each row: we advise you not to perform slow calculations (avoid the accesses to the database for example).
  • ..TotalsEnabled is used to forbid or force the automatic or custom calculations performed in a Table control.
  • The following syntax is used to retrieve the value of the custom calculation for a column:
    <Table Name>.<Column Name>[Row Number]
    where <Row Number> corresponds to the row subscript returned by TableFormulaAdd.

Position of calculation row

To configure the position of automatic or custom column calculations:
  1. Display the "General" tab of the Table control (to do so, select the name of the Table control and click the "General" tab).
  2. Specify the location of totals. To display the results:
    • in one or more rows directly added after the last control row, check "In the table, after the last row".
      These rows are visible:
      • at the bottom of the Table control if the control includes no vertical scrollbar.
      • when the vertical scrollbar is located at the very bottom if the Table control includes a vertical scrollbar.
    • below the Table control, check "Below the table".
      These rows are always visible.
    • you also have the ability to perform column calculations without displaying them ("No display" option).
  3. Validate the description window of Table control.

Customizing the calculation row

You have the ability to customize (caption, color, font, height, ...):
  • the added row by using the following syntax:
    <Table Name>[Row Number]..<Property> = <New Value>
  • the cell containing the result by using the following syntax:
    <Table Name>.<Column Name>[Row Number]..<Property> = <New Value>

    Caution: the first column contains the caption of the calculation if it exists.
where:
  • <Row Number> corresponds to the row subscript returned by TableFormulaAdd.
  • <Property> can correspond to one of the following properties:
    ColorUsed to find out and modify the color of the text displayed in a calculation cell.
    BrushColorUsed to find out and modify the background color of a calculation cell.
    StateUsed to find out and modify the display status of the row containing the calculation cell.
    HeightUsed to find out and modify the height of a calculation cell.
    WidthUsed to find out and modify the width of a calculation cell.
    CaptionUsed to find out and modify the caption of the row containing a calculation cell.
    NameUsed to find out the name of a calculation cell.
    NoteUsed to find out and modify the notes associated with a calculation cell.
    FontAllows you to find out and modify the font used in a calculation cell.
    FontStrikeOutUsed to find out and modify the "StrikeOut" attribute for a calculation cell.
    FontCondensedUsed to find out whether the characters of column elements are condensed or not, and to condense (or not) the characters of column elements.
    FontExtendedUsed to find out whether the characters of column elements are extended or not, and to extend (or not) the characters of column elements.
    FontBoldUsed to find out and modify the "Bold" attribute for the column elements.
    FontItalicUsed to find out and modify the "Italic" attribute for the column elements.
    FontLargeUsed to find out whether the characters of column elements are enlarged or not, and to enlarge (or not) the characters of column elements.
    FontNameUsed to find out and modify the font used for the column elements.
    FontUnderlinedUsed to find out and modify the "Underline" attribute for the column elements.
    FontSizeUsed to find out and modify the size of the font used for the column elements.
    VisibleUsed to find out whether a column is visible and to make a column visible/invisible.

Deleting the custom calculation rows

To delete the custom calculation rows, use TableFormulaDeleteAll.
Exporting the results of calculations

Export via the AAF (Automatic Application Features) of Table control

The popup menu of Table and TreeView Table controls proposes several options used to export the control content.
During this export, the results of custom calculations are exported.
Note: Only the value is exported, not the caption.

Export via the WLanguage functions

Several WLanguage functions can be used to export the content of a Table control in a specific format (Word, Excel, XML, ...). During this export, the rows corresponding to calculations are also exported by default.
To avoid exporting the calculation rows, all you have to do is specify the taNoTotal constant in the following functions:
Versions 12 and later
TableToClipboard
New in version 12
TableToClipboard
TableToClipboard
Copies the content of a Table or TreeView Table control into the clipboard.
Versions 09 and later
TableToExcel
New in version 09
TableToExcel
TableToExcel
Creates an Excel file from the data found in a Table or Treeview Table control .
Versions 12 and later
TableToText
New in version 12
TableToText
TableToText
Creates a character string from the data found in a Table or TreeView Table control.
Versions 09 and later
TableToWord
New in version 09
TableToWord
TableToWord
Creates a Word file (.RTF) from the data found in a Table or Treeview Table control.
Versions 09 and later
TableToXML
New in version 09
TableToXML
TableToXML
Creates an XML file from the data found in a Table or TreeView Table control .
Minimum required version
  • Version 22
Comments
Click [Add] to post a comment