SOMAR DADOS DE UM TEXTBOX E DE FLEXGRID ??
alguem tem me dá algumas dicas para trablhar com casas decimasi para somar resultados . obrigado.
Neste exemplo estou somando uma coluna de um flexgrid e lançando os valores em um textbox.
Também estou formatando a coluna do flexgrid e a da textbox:
Seria isto que você precisa ??????
Set BancoDeDados = OpenDatabase(App.Path & "\bolao.MDB", False)
Set TBSaldo = BancoDeDados.OpenRecordset("select Matricula,Nome,sum (Saldo) from Saldo Where Data >= #" & Format(DataInicial, "mm/dd/yy") & "# and data<= #" & Format(DataFinal, "mm/dd/yy") & "# and Equipe='" & Equipe.Text & "' group by Matricula,Nome order by sum (Saldo)asc")
If Not TBSaldo.EOF Then
With MSFlexGrid1
.Rows = 1
.Cols = 4
.ColWidth(0) = 500
.ColWidth(1) = 800
.ColWidth(2) = 3000
.ColWidth(3) = 1200
.TextMatrix(0, 0) = "Lugar"
.TextMatrix(0, 1) = "Matricula"
.TextMatrix(0, 2) = "Nome"
.TextMatrix(0, 3) = "Valor"
End With
i = 1
Do While Not TBSaldo.EOF
With MSFlexGrid1
.Rows = i + 1
.ColAlignment(0) = flexAlignCenterCenter ' alinha coluna
.TextMatrix(i, 0) = i - 0 ' autonumeração colocar zero para poder começar com 1
.ColAlignment(1) = flexAlignCenterCenter
.TextMatrix(i, 1) = TBSaldo(0)
.ColAlignment(2) = flexAlignLeftCenter
.TextMatrix(i, 2) = TBSaldo(1)
.ColAlignment(3) = flexAlignCenterCenter
.TextMatrix(i, 3) = Format(TBSaldo(2), "Currency")
.Col = 3
.Row = i
.CellForeColor = vbRed
.CellFontBold = True
End With
i = i + 1
SomaColuna = SomaColuna + TBSaldo(2)
TBSaldo.MoveNext
Loop
' Textbox com o total da coluna
Saldo.Text = Format(SomaColuna, "currency")
End If
Também estou formatando a coluna do flexgrid e a da textbox:
Seria isto que você precisa ??????
Set BancoDeDados = OpenDatabase(App.Path & "\bolao.MDB", False)
Set TBSaldo = BancoDeDados.OpenRecordset("select Matricula,Nome,sum (Saldo) from Saldo Where Data >= #" & Format(DataInicial, "mm/dd/yy") & "# and data<= #" & Format(DataFinal, "mm/dd/yy") & "# and Equipe='" & Equipe.Text & "' group by Matricula,Nome order by sum (Saldo)asc")
If Not TBSaldo.EOF Then
With MSFlexGrid1
.Rows = 1
.Cols = 4
.ColWidth(0) = 500
.ColWidth(1) = 800
.ColWidth(2) = 3000
.ColWidth(3) = 1200
.TextMatrix(0, 0) = "Lugar"
.TextMatrix(0, 1) = "Matricula"
.TextMatrix(0, 2) = "Nome"
.TextMatrix(0, 3) = "Valor"
End With
i = 1
Do While Not TBSaldo.EOF
With MSFlexGrid1
.Rows = i + 1
.ColAlignment(0) = flexAlignCenterCenter ' alinha coluna
.TextMatrix(i, 0) = i - 0 ' autonumeração colocar zero para poder começar com 1
.ColAlignment(1) = flexAlignCenterCenter
.TextMatrix(i, 1) = TBSaldo(0)
.ColAlignment(2) = flexAlignLeftCenter
.TextMatrix(i, 2) = TBSaldo(1)
.ColAlignment(3) = flexAlignCenterCenter
.TextMatrix(i, 3) = Format(TBSaldo(2), "Currency")
.Col = 3
.Row = i
.CellForeColor = vbRed
.CellFontBold = True
End With
i = i + 1
SomaColuna = SomaColuna + TBSaldo(2)
TBSaldo.MoveNext
Loop
' Textbox com o total da coluna
Saldo.Text = Format(SomaColuna, "currency")
End If
Assim estou somando uma coluna do FlexGrid e mostrando o total
em uma label
OBS.
a vantagem é que você pode enviar quantos dados quiser que a soma é atualizada, ou remover.
Dim x As Integer
Dim x1 As Integer
Dim total As Double
Dim selct As Byte
selct = FlexGrid.RowSel
x = selct
FlexGrid.RemoveItem (x)
For x1 = 1 To FlexGrid.Rows - 1
If FlexGrid.TextMatrix(x1, 3) <> "" Then
total = Format(total, "#,##0.00") + CSng(FlexGrid.TextMatrix(x1, 3))
lblSubTotal.Caption = Format(total, "#,##0.00")
End If
Next
em uma label
OBS.
a vantagem é que você pode enviar quantos dados quiser que a soma é atualizada, ou remover.
Dim x As Integer
Dim x1 As Integer
Dim total As Double
Dim selct As Byte
selct = FlexGrid.RowSel
x = selct
FlexGrid.RemoveItem (x)
For x1 = 1 To FlexGrid.Rows - 1
If FlexGrid.TextMatrix(x1, 3) <> "" Then
total = Format(total, "#,##0.00") + CSng(FlexGrid.TextMatrix(x1, 3))
lblSubTotal.Caption = Format(total, "#,##0.00")
End If
Next
Tópico encerrado , respostas não são mais permitidas