CALCULO NO VB

ANDREW 21/11/2004 03:08:12
#51332
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
USUARIO.EXCLUIDOS 21/11/2004 03:33:44
#51334
  
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.
USUARIO.EXCLUIDOS 21/11/2004 03:37:26
#51335
Resposta escolhida
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