CALCULO NO VB
Por favor quero saber como faço para calcular o total de um caixa de supermercado, como no seguinte exemplo: Ao digitar o preço e quantidade do produto comprado, ele multiplicaria os valores que iria para o total, depois calcularia outro registro multiplicando a quantidade pelo preço e somado ao total....muito obrigado pela atenção
Private Sub Command1_Click()
Dim Total As Currency
Dim ValorProduto As Currency
Dim Qtd As Integer
ValorProduto = CCur(txt_Valor.Text)
Qtd = CInt(txt_Quant.Text)
Total = lbl_Total.Caption + (Qtd * ValorProduto)
lbl_Total.Caption = Format(Total, "#0.00")
End Sub
Private Sub Form_Load()
lbl_Total.Caption = "0,00"
End Sub
Existem diversas outras formas, como ir lançando os resultados totais e parciais em registros; declarar como Static o Valor total, etc.
Os cálculos do command poderão também ficar no evento KeyDown do Text:
Private Sub txt_Valor_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> 13 Then Exit Sub
Dim Total As Currency
Dim ValorProduto As Currency
Dim Qtd As Integer
ValorProduto = CCur(txt_Valor.Text)
Qtd = CInt(txt_Quant.Text)
Total = lbl_Total.Caption + (Qtd * ValorProduto)
lbl_Total.Caption = Format(Total, "#0.00")
txt_Quant.Text = ""
txt_Quant.SetFocus
txt_Valor = ""
End Sub
Tópico encerrado , respostas não são mais permitidas