I'm doing a work using Visual Basic 6.0 work, that has the objective of calculating the total value of an ordering. However I can't do the total sum of the diferent values including in a label (putting the total into the txtBox), it always gives me the last value. Truly will appreciate your help
Here goes the cod:
Expand|Select|Wrap|Line Numbers
- Private Sub cmbCodigo_DropDown()
- txtQuantidade.Enabled = True
- End Sub
- Private Sub Form_Load()
- cmbCodigo.AddItem "1 - Maçã Goldem"
- cmbCodigo.AddItem "2 - Maçã Royal Gala"
- cmbCodigo.AddItem "3 - Pêra Rocha"
- cmbCodigo.AddItem "4 - Laranja"
- cmbCodigo.AddItem "5 - Tangerina"
- cmbCodigo.AddItem "6 - Kiwi"
- cmbCodigo.AddItem "7 - Banana da Madeira"
- cmbCodigo.AddItem "8 - Morangos"
- cmbCodigo.AddItem "9 - Meloa Galia"
- cmdRegisto.Enabled = False
- cmdLimpar.Enabled = False
- txtQuantidade.Enabled = False
- End Sub
- Private Sub cmdLimpar_Click()
- txtQuantidade.Text = ""
- lblCalculo.Caption = ""
- txtTotal.Text = ""
- cmdLimpar.Enabled = False
- End Sub
- Private Sub cmdRegisto_Click()
- 'Declaração de variáveis'
- Dim sngquant As Single
- Dim sngResultado As Single
- Dim sngCod As Single
- Dim sngSum As Single
- Dim sngParcela As Single
- Dim sngValor As Single
- Dim sngParcela1 As Single
- 'Torna-se necessário validarmos os dados da quantidade para tal vamos utilizar a instrução if'
- 'Processamento'
- If IsNumeric(txtQuantidade.Text) Then '(Caso seja numérica, vamos fazer o tratamento do input'
- sngquant = txtQuantidade.Text
- If txtQuantidade.Text = "" Then 'Caso a caixa esteja vazia vamos mostrar uma message box'
- MsgBox "Por favor insira a quantidade", vbExclamation
- lblCalculo.Caption = ""
- Else 'Por fim, vamos definir um intervalo dos valores da quantidade'
- If txtQuantidade.Text < 1 Or txtQuantidade.Text > 150 Then
- MsgBox "A quantidade deve estar compreendida entre 1 e 150 kilos, por favor verifique os dados", vbExclamation
- lblCalculo.Caption = " "
- End If
- End If
- Else
- MsgBox "Insira um valor númerico, por favor", vbExclamation '(message box que aparece caso o valor não seja numérico'
- lblCalculo.Caption = " "
- End If
- sngCodigo = cmbCodigo.Text
- Select Case sngCodigo
- Case Is = "1 - Maçã Goldem"
- sngValor = (1.5 + 1.5) * 0.21 + (1.5 + 1.5)
- Case Is = "2 - Maçã Royal Gala"
- sngValor = (1.74 + 1.5) * 0.21 + (1.74 + 1.5)
- Case Is = "3 - Pêra Rocha"
- sngValor = (1.5 + 1.5) * 0.21 + (1.5 + 1.5)
- Case Is = "4 - Laranja"
- sngValor = (0.85 + 1.5) * 0.21 + (0.85 + 1.5)
- Case Is = "5 - Tangerina"
- sngValor = (0.8 + 1.5) * 0.21 + (0.8 + 1.5)
- Case Is = "6 - Kiwi"
- sngValor = (1 + 1.5) * 0.21 + (1 + 1.5)
- Case Is = "7 - Banana da Madeira"
- sngValor = (0.9 + 1.5) * 0.21 + (0.9 + 1.5)
- Case Is = "8 - Morangos"
- sngValor = (1.5 + 2.5) * 0.21 + (2.5 + 1.5)
- Case Is = "9 - Meloa Galia"
- sngValor = (1.5 + 2) * 0.21 + (2 + 1.5)
- End Select
- txtTotal.Text = sngParcela1
- sngParcela = sngquant * sngValor
- sngParcela1 = sngParcela1 + sngParcela
- 'Tratamento de Output's
- txtTotal.Text = sngParcela1 & " €"
- lblCalculo.Caption = lblCalculo.Caption & cmbCodigo.Text _
- & " " & txtQuantidade.Text & " x " & sngValor & " € " _
- & sngParcela & " €" & vbNewLine _
- 'Prepara a introdução de novos dados na caixa de texto
- txtQuantidade.Text = " "
- cmbCodigo.SetFocus
- End Sub
- Private Sub cmdSair_Click()
- Unload Me
- End Sub
- Private Sub txtQuantidade_Change()
- If txtQuantidade.Text <> "" _
- Then cmdRegisto.Enabled = True
- cmdLimpar.Enabled = True
- End Sub
Best wishes
Jessica