PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
This content has been translated automatically. Click here to view the French version.
  • 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_MaTable)
nLigne is int
nLigne = TableFormulaAdd(TABLE_MaTable.COL_Num, "Moyenne positive", ProcInit, ProcAjout, ProcFin)
// Changement de la couleur de fond de la ligne du calcul personnalisé
COL_Num[nLigne].CouleurFond = LightRed
 
nCompteur is int
INTERNAL PROCÉDURE ProcInit()
nCompteur = 0
RETURN 0
END
 
INTERNAL PROCÉDURE ProcAjout(Accumulateur, ValeurCol)
// Ignore les négatifs ou NULL
IF (ValeurCol <= 0) RETURN Accumulateur
nCompteur++
RETURN Accumulateur + ValeurCol
END
INTERNAL PROCÉDURE ProcFin(Accumulateur)
IF nCompteur = 0 THEN RETURN 0
// Calcul de la moyenne
RETURN  Accumulateur/nCompteur
END
nLigne2 is int
nLigne2 = TableFormulaAdd(TABLE_ChampTable.COL_Heure, "Durée moyenne", Null, ...
DuréeMoyenne_Itération, DuréeMoyenne_Fin)
 
INTERNAL PROCÉDURE DuréeMoyenne_Itération(Accumulateur, ValeurCol)
RETURN Accumulateur + [TAB] + ValeurCol
END
 
INTERNAL PROCÉDURE DuréeMoyenne_Fin(Accumulateur)
nSomme is 8-byte int
nNbValides is int
FOR EACH STRING sValeur OF Accumulateur SÉPARÉE BY TAB
IF TimeValid(sValeur) THEN
nSomme += TimeToInteger(sValeur)
nNbValides++
END
END
RETURN TimeToString(IntegerToTime(nSomme/nNbValides), "HH:MM:SS")
END
Syntax
<Result> = TableFormulaAdd(<Column> , <Calculation caption> , <Initialization> , <Iteration> , <Ending>)
<Result>: Integer
Subscript of the row containing the formula.
<Column>: Control name
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 the Procedure WLanguage (also called "callback") called to initialize the formula. This procedure has the following format:
    PROCEDURE <Nom de la procédure> ()
    // votre code

    RENVOYER <Valeur d'initialisation Accumulateur>

    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 the Procedure WLanguage (also called "callback") called for each iteration of the formula (each row of the table). This Procedure has an access only in get on the columns of the row. This procedure has the following format:
    PROCEDURE <Nom de la procédure> (<Accumulateur>, <Valeur de la colonne>)
    // Appelée pour chaque ligne de la table
    // Votre code

    RENVOYER <Nouvelle valeur Accumulateur>

    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 Procedure WLanguage (also called "callback") called to end the formula. This procedure has the following format:
    PROCEDURE <Nom de la procédure> ()
    // votre code

    RENVOYER <Valeur de fin Accumulateur>

    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.
Remark: 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, ...):
<Champ Table>[Numéro ligne].<Propriété> = <Nouvelle valeur>
where <Property> can correspond to one of the properties that can be used on a column of a Table control. For more details, see Programming custom calculations in Table controls.
Business / UI classification: UI Code
Component: wd260obj.dll
Minimum version required
  • Version 22
This page is also available for…
Comments
Cascading calculations
To have cascading values calculated in a table using TableFormulaAdd() the data fill must be "Loaded in memory" otherwise it will not calculate and you will see only zeroes (0) in the calculated column values.
This is not indicated in this help page so, I decided to point it out.
JoeData
17 Mar. 2021