PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Conditions for adding the row containing the custom calculation formula
  • Recalculating data
  • Customizing the calculation row
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
Adds a calculated row into a Table control by providing the procedures for custom calculations.
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
nRow2 is int
nRow2 = TableFormulaAdd(TABLE_TableControl.COL_Time, "Average duration", Null, ...
AverageDuration_Iteration, AverageDuration_End)

INTERNAL PROCÉDURE AverageDuration_Iteration(Accumulator, ColValue)
RESULT Accumulator+[TAB]+ColValue
END

INTERNAL PROCÉDURE AverageDuration_End(Accumulator)
nSum is 8-byte int
nNbValid is int
FOR EACH STRING sValue OF Accumulator SEPARATED BY TAB
IF ValidTime(sValue) THEN
nSum += TimeToInteger(sValue)
nNbValid++
END
END
RESULT TimeToString(IntegerToTime(nSum/nNbValid), "HH:MM:SS")
END
Syntax
<Result> = TableFormulaAdd(<Column Name> , <Calculation Caption> , <Initialization> , <Iteration> , <Ending>)
<Result>: Integer
Subscript of the row containing the formula.
<Column Name>: Character string (with or without quotes)
Name of column into which the formula will be added.
If this parameter corresponds to an empty string (""), the column to which the current process belongs will be used.
<Calculation Caption>: Character string (with quotes)
Caption of the additional row where the calculation will be displayed.
If this caption does not exist, the row will be created.
If this caption exists but not for the specified column, the calculation is displayed in the existing row but for the specified column.
If this caption exists for the specified column, a WLanguage error occurs.
<Initialization>: Character string (with or without quotes)
  • Name of WLanguage procedure ("callback" procedure) that will be called to initialize the formula. This procedure has the following format:
    PROCEDURE <Procedure Name> ()
    // your code

    RESULT <Initialization value Accumulator>

    where <Initialization value Accumulator> is the value to return for the first iteration of the calculation.
  • NULL if the formula requires no initialization process.
<Iteration>: Character string (with or without quotes)
  • Name of WLanguage procedure ("callback" procedure) that will be called for each iteration of the formula (each table row). This procedure has the following format:
    PROCEDURE <Procedure Name>(<Accumulator>, <Column Value>)
    // Called for each table row
    // Your code

    RESULT <New value Accumulator>

    where:
    • <Accumulator> is the value coming from the previous calculation (initialization or previous iteration).
    • <Column Value> is the value of the current column used to calculate this iteration.
    • <New value Accumulator> is the new value to return for the next iteration or at the end of calculation.
  • NULL if the formula requires no initialization process.
<Ending>: Character string (with or without quotes)
  • Name of the WLanguage procedure ("callback" procedure) that will be called to end the formula. This procedure has the following format:
    PROCEDURE <Procedure Name> ()
    // your code

    RESULT <End value Accumulator>

    where <End value Accumulator> is the value to return corresponding to the value of end of calculation.
  • NULL if the formula requires no ending process.
Remarks

Conditions for adding the row containing the custom calculation formula

  • If the calculation named <Calculation Caption> does not exist in the table, a new calculation row is added below the table (after the existing calculations).
  • If a calculation named <Calculation Caption> was already defined for another column, the calculation is displayed for the specified column in the existing calculation row.
  • If a calculation named <Calculation Caption> was already defined for the same column, a WLanguage error occurs.
  • Only 5 custom calculation rows can be added.
Note: This function can be used:
  • on the columns found in a Table or TreeView Table control.
  • on the columns found in the memory or browsing controls.

Recalculating data

The custom calculation rows are automatically recalculated as soon as the content of the 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).

Customizing the calculation row

The following syntax is used to customize the added row (caption, color, font, height, ...):
<Table Name>[Row Number]..<Property> = <New Value>
where <Property> can correspond to one of the properties that can be used on a column found in a Table control. See Programming custom calculations in the tables for more details.
Components
WINDEVReports and Queries wd230obj.dll
Minimum required version
  • Version 22
This page is also available for…
Comments
Click [Add] to post a comment