Howdy there:
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:
[code=vb]
Private Sub cmbCodigo_DropD own()
txtQuantidade.E nabled = True
End Sub
Private Sub Form_Load()
cmbCodigo.AddIt em "1 - Maçã Goldem"
cmbCodigo.AddIt em "2 - Maçã Royal Gala"
cmbCodigo.AddIt em "3 - Pêra Rocha"
cmbCodigo.AddIt em "4 - Laranja"
cmbCodigo.AddIt em "5 - Tangerina"
cmbCodigo.AddIt em "6 - Kiwi"
cmbCodigo.AddIt em "7 - Banana da Madeira"
cmbCodigo.AddIt em "8 - Morangos"
cmbCodigo.AddIt em "9 - Meloa Galia"
cmdRegisto.Enab led = False
cmdLimpar.Enabl ed = False
txtQuantidade.E nabled = False
End Sub
Private Sub cmdLimpar_Click ()
txtQuantidade.T ext = ""
lblCalculo.Capt ion = ""
txtTotal.Text = ""
cmdLimpar.Enabl ed = False
End Sub
Private Sub cmdRegisto_Clic k()
'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(txtQu antidade.Text) Then '(Caso seja numérica, vamos fazer o tratamento do input'
sngquant = txtQuantidade.T ext
If txtQuantidade.T ext = "" Then 'Caso a caixa esteja vazia vamos mostrar uma message box'
MsgBox "Por favor insira a quantidade", vbExclamation
lblCalculo.Capt ion = ""
Else 'Por fim, vamos definir um intervalo dos valores da quantidade'
If txtQuantidade.T ext < 1 Or txtQuantidade.T ext > 150 Then
MsgBox "A quantidade deve estar compreendida entre 1 e 150 kilos, por favor verifique os dados", vbExclamation
lblCalculo.Capt ion = " "
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.Capt ion = " "
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.Capt ion = lblCalculo.Capt ion & cmbCodigo.Text _
& " " & txtQuantidade.T ext & " x " & sngValor & " € " _
& sngParcela & " €" & vbNewLine _
'Prepara a introdução de novos dados na caixa de texto
txtQuantidade.T ext = " "
cmbCodigo.SetFo cus
End Sub
Private Sub cmdSair_Click()
Unload Me
End Sub
Private Sub txtQuantidade_C hange()
If txtQuantidade.T ext <> "" _
Then cmdRegisto.Enab led = True
cmdLimpar.Enabl ed = True
End Sub
[/code]
Hoping to hear from you soon
Best wishes
Jessica
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:
[code=vb]
Private Sub cmbCodigo_DropD own()
txtQuantidade.E nabled = True
End Sub
Private Sub Form_Load()
cmbCodigo.AddIt em "1 - Maçã Goldem"
cmbCodigo.AddIt em "2 - Maçã Royal Gala"
cmbCodigo.AddIt em "3 - Pêra Rocha"
cmbCodigo.AddIt em "4 - Laranja"
cmbCodigo.AddIt em "5 - Tangerina"
cmbCodigo.AddIt em "6 - Kiwi"
cmbCodigo.AddIt em "7 - Banana da Madeira"
cmbCodigo.AddIt em "8 - Morangos"
cmbCodigo.AddIt em "9 - Meloa Galia"
cmdRegisto.Enab led = False
cmdLimpar.Enabl ed = False
txtQuantidade.E nabled = False
End Sub
Private Sub cmdLimpar_Click ()
txtQuantidade.T ext = ""
lblCalculo.Capt ion = ""
txtTotal.Text = ""
cmdLimpar.Enabl ed = False
End Sub
Private Sub cmdRegisto_Clic k()
'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(txtQu antidade.Text) Then '(Caso seja numérica, vamos fazer o tratamento do input'
sngquant = txtQuantidade.T ext
If txtQuantidade.T ext = "" Then 'Caso a caixa esteja vazia vamos mostrar uma message box'
MsgBox "Por favor insira a quantidade", vbExclamation
lblCalculo.Capt ion = ""
Else 'Por fim, vamos definir um intervalo dos valores da quantidade'
If txtQuantidade.T ext < 1 Or txtQuantidade.T ext > 150 Then
MsgBox "A quantidade deve estar compreendida entre 1 e 150 kilos, por favor verifique os dados", vbExclamation
lblCalculo.Capt ion = " "
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.Capt ion = " "
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.Capt ion = lblCalculo.Capt ion & cmbCodigo.Text _
& " " & txtQuantidade.T ext & " x " & sngValor & " € " _
& sngParcela & " €" & vbNewLine _
'Prepara a introdução de novos dados na caixa de texto
txtQuantidade.T ext = " "
cmbCodigo.SetFo cus
End Sub
Private Sub cmdSair_Click()
Unload Me
End Sub
Private Sub txtQuantidade_C hange()
If txtQuantidade.T ext <> "" _
Then cmdRegisto.Enab led = True
cmdLimpar.Enabl ed = True
End Sub
[/code]
Hoping to hear from you soon
Best wishes
Jessica
Comment