AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Controles, páginas y ventanas / Funciones Tabla
  • Conditions for adding the row containing the custom calculation formula
  • Recalculating data
  • Customizing the calculation row
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Adds a calculated row to a Table or TreeView Table control by providing custom calculation procedures.
Ejemplo
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].BackgroundColor = LightRed

nCounter is int
INTERNAL PROCEDURE ProcInit() 
	nCounter = 0
	RETURN 0
END

INTERNAL PROCEDURE ProcAdd(Accumulator, ColValue) 
	// Ignores the negative numbers or NULL
	IF (ColValue <= 0) RETURN Accumulator
	nCounter++
	RETURN Accumulator + ColValue
END
INTERNAL PROCEDURE ProcEnd(Accumulator) 
	IF nCounter = 0 THEN RETURN 0
	// Calculate the mean
	RETURN Accumulator/nCounter
END
nRow2 is int
nRow2 = TableFormulaAdd(TABLE_TableControl.COL_Time, "Average duration", Null, ...
			AverageDuration_Iteration, AverageDuration_End)

INTERNAL PROCEDURE AverageDuration_Iteration(Accumulator, ColValue)
	RETURN Accumulator + [TAB] + ColValue
END

INTERNAL PROCEDURE 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
	RETURN TimeToString(IntegerToTime(nSum/nNbValid), "HH:MM:SS")
END
Sintaxis
<Result> = TableFormulaAdd(<Column> , <Calculation caption> , <Initialization> , <Iteration> , <Ending>)
<Result>: Integer
Index 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
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>: Procedure name or NULL
  • Name of the WLanguage procedure ("callback") called to initialize the formula. This procedure has the following format:
    PROCEDURE <Procedure name> ()
    // your code

    RETURN <Initialization value Accumulator>

    where <Initialization value Accumulator> is the return value for the first iteration of the calculation.
  • NULL if the formula requires no initialization process.
<Iteration>: Procedure name or NULL
  • Name of the WLanguage procedure ("callback") called for each iteration of the formula (each row of the Table control). This procedure has read-only access to the columns of each row. This procedure has the following format:
    PROCEDURE <Procedure name>(<Accumulator>, <Column value>)
    // Called for each row in the Table control
    // Your code

    RETURN <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 iteration process.
<Ending>: Character string
  • Name of the WLanguage procedure ("callback") called to end the formula. This procedure has the following format:
    PROCEDURE <Procedure name>  (<Accumulator>)
    // your code

    RETURN <End value Accumulator>

    where:
    • <Accumulator> is the value coming from the previous calculation (initialization or previous iteration).
    • <End value Accumulator> is the return value that corresponds to the end value of the calculation.
  • NULL if the formula requires no ending process.
Observaciones

Conditions for adding the row containing the custom calculation formula

  • If the calculation named <Calculation caption> does not exist in the Table control, a new calculation row is added below the Table control (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 of a data-bound Table or TreeView Table control.
  • on the columns of a Table or TreeView Table control populated programmatically.

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 line: it is recommended not to perform calculations too slowly (for example, to avoid database accesses).

Customizing the calculation row

The following syntax is used to customize the added row (caption, color, font, height, ...):
<Table control>[Row number].<Property> = <New value>
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.
Clasificación Lógica de negocio / UI: Código UI
Componente: wd300obj.dll
Versión mínima requerida
  • Versión 22
Esta página también está disponible para…
Comentarios
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 03 2021

Última modificación: 13/06/2025

Señalar un error o enviar una sugerencia | Ayuda local