Campos calculados en dbgrid

Santiago
04 de Agosto del 2004
Hola a todos, me gustaria saber como sumar o restar o hacer cualquier operacion matematica com las celdas de dbgrid, o cualquier objeto parecido.

RBASIC
04 de Agosto del 2004
MI QUERIDO AMIGO TE ENVIO UN EJEMPLO
Sub Fnc_RestorePrecios(pGrid As MSFlexGrid, PColId As Byte, PColDesPreU As Byte, PColOriPreU As Byte, PColImporte As Integer, Optional PColCant As Byte, Optional ByRef pTotal As Double, Optional pFormatInt As String = "#########0.00###", Optional pFormatExt As String = "#,###,###,##0.00")
Dim X As Long, xSum As Double
Dim xImp As Double
If PColImporte > -1 Then
For X = 1 To pGrid.Rows - 1
If pGrid.TextMatrix(X, PColId) <> "" Then
pGrid.TextMatrix(X, PColDesPreU) = Format(pGrid.TextMatrix(X, PColOriPreU), pFormatExt)
pGrid.TextMatrix(X, PColImporte) = Format(Val(Format(pGrid.TextMatrix(X, PColCant), pFormatInt)) * Val(Format(pGrid.TextMatrix(X, PColOriPreU), pFormatInt)), pFormatExt)
xImp = Val(Format(pGrid.TextMatrix(X, PColCant), pFormatInt)) * Val(Format(pGrid.TextMatrix(X, PColOriPreU), pFormatInt))
xSum = xSum + xImp
End If
Next X
Else
For X = 1 To pGrid.Rows - 1
If pGrid.TextMatrix(X, PColId) <> "" Then
pGrid.TextMatrix(X, PColDesPreU) = Format(pGrid.TextMatrix(X, PColOriPreU), pFormatExt)
xImp = Val(Format(pGrid.TextMatrix(X, PColOriPreU), pFormatInt))
xSum = xSum + xImp
End If
Next X
End If
pTotal = xSum
End Sub