473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Doing Sum in VB6

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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbCodigo_DropDown()
  2.     txtQuantidade.Enabled = True
  3. End Sub
  4.  
  5. Private Sub Form_Load()
  6. cmbCodigo.AddItem "1 - Maçã Goldem"
  7. cmbCodigo.AddItem "2 - Maçã Royal Gala"
  8. cmbCodigo.AddItem "3 - Pêra Rocha"
  9. cmbCodigo.AddItem "4 - Laranja"
  10. cmbCodigo.AddItem "5 - Tangerina"
  11. cmbCodigo.AddItem "6 - Kiwi"
  12. cmbCodigo.AddItem "7 - Banana da Madeira"
  13. cmbCodigo.AddItem "8 - Morangos"
  14. cmbCodigo.AddItem "9 - Meloa Galia"
  15.  
  16. cmdRegisto.Enabled = False
  17. cmdLimpar.Enabled = False
  18. txtQuantidade.Enabled = False
  19. End Sub
  20.  
  21. Private Sub cmdLimpar_Click()
  22. txtQuantidade.Text = ""
  23. lblCalculo.Caption = ""
  24. txtTotal.Text = ""
  25. cmdLimpar.Enabled = False
  26. End Sub
  27.  
  28. Private Sub cmdRegisto_Click()
  29. 'Declaração de variáveis'
  30.     Dim sngquant As Single
  31.     Dim sngResultado As Single
  32.     Dim sngCod As Single
  33.     Dim sngSum As Single
  34.     Dim sngParcela As Single
  35.     Dim sngValor As Single
  36.     Dim sngParcela1 As Single
  37.  
  38. 'Torna-se necessário validarmos os dados da quantidade para tal vamos utilizar a instrução if'
  39. 'Processamento'
  40.   If IsNumeric(txtQuantidade.Text) Then '(Caso seja numérica, vamos fazer o tratamento do input'
  41.     sngquant = txtQuantidade.Text
  42.  
  43.         If txtQuantidade.Text = "" Then 'Caso a caixa esteja vazia vamos mostrar uma message box'
  44.         MsgBox "Por favor insira a quantidade", vbExclamation
  45.         lblCalculo.Caption = ""
  46.     Else 'Por fim, vamos definir um intervalo dos valores da quantidade'
  47.         If txtQuantidade.Text < 1 Or txtQuantidade.Text > 150 Then
  48.         MsgBox "A quantidade deve estar compreendida entre 1 e 150 kilos, por favor verifique os dados", vbExclamation
  49.        lblCalculo.Caption = " "
  50.        End If
  51.     End If
  52.  
  53.     Else
  54. MsgBox "Insira um valor númerico, por favor", vbExclamation '(message box que aparece caso o valor não seja numérico'
  55. lblCalculo.Caption = " "
  56. End If
  57.  
  58. sngCodigo = cmbCodigo.Text
  59.  
  60.     Select Case sngCodigo
  61. Case Is = "1 - Maçã Goldem"
  62.     sngValor = (1.5 + 1.5) * 0.21 + (1.5 + 1.5)
  63. Case Is = "2 - Maçã Royal Gala"
  64.     sngValor = (1.74 + 1.5) * 0.21 + (1.74 + 1.5)
  65. Case Is = "3 - Pêra Rocha"
  66.     sngValor = (1.5 + 1.5) * 0.21 + (1.5 + 1.5)
  67. Case Is = "4 - Laranja"
  68.     sngValor = (0.85 + 1.5) * 0.21 + (0.85 + 1.5)
  69. Case Is = "5 - Tangerina"
  70.     sngValor = (0.8 + 1.5) * 0.21 + (0.8 + 1.5)
  71. Case Is = "6 - Kiwi"
  72.     sngValor = (1 + 1.5) * 0.21 + (1 + 1.5)
  73. Case Is = "7 - Banana da Madeira"
  74.     sngValor = (0.9 + 1.5) * 0.21 + (0.9 + 1.5)
  75. Case Is = "8 - Morangos"
  76.     sngValor = (1.5 + 2.5) * 0.21 + (2.5 + 1.5)
  77. Case Is = "9 - Meloa Galia"
  78.     sngValor = (1.5 + 2) * 0.21 + (2 + 1.5)
  79.    End Select
  80. txtTotal.Text = sngParcela1
  81. sngParcela = sngquant * sngValor
  82. sngParcela1 = sngParcela1 + sngParcela
  83.  'Tratamento de Output's
  84.     txtTotal.Text = sngParcela1 & " €"
  85.     lblCalculo.Caption = lblCalculo.Caption & cmbCodigo.Text _
  86.                           & "             " & txtQuantidade.Text & " x " & sngValor & " €        " _
  87.                          & sngParcela & " €" & vbNewLine _
  88.  
  89.   'Prepara a introdução de novos dados na caixa de texto
  90.     txtQuantidade.Text = " "
  91.     cmbCodigo.SetFocus
  92.  
  93.  
  94. End Sub
  95.  
  96. Private Sub cmdSair_Click()
  97. Unload Me
  98. End Sub
  99.  
  100. Private Sub txtQuantidade_Change()
  101. If txtQuantidade.Text <> "" _
  102.     Then cmdRegisto.Enabled = True
  103.         cmdLimpar.Enabled = True
  104.  End Sub
  105.  
Hoping to hear from you soon
Best wishes
Jessica
Feb 28 '08 #1
1 1538
jamesd0142
469 256MB
if label1.text = "12"
textbox1.text = "13"

to sum them and store in txtboxtotal:

txtboxtotal.text = cint(label1.text) + cint(textbox1.text)
txtboxtotal.text = "25"
------------------------------------------------------------------------------------

now say you want to add another value to total;

dim amount as integer
amount = "35"

txtboxtotal.text = cint( txtboxtotal.text) + cint(amount)

James
Feb 28 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Benjamin | last post by:
Hello, I need some advice on a financial application I'm doing. First, I suppose I should give a little background so you know where I'm coming from. For 5 years I earned my living doing COBOL...
3
by: Amy G | last post by:
I have a whole bunch of tuples that look something like this, aTuple = ('1074545869.6580.msg', 't_bryan_pw@gmcc.ab.ca', 'Your one stop prescriptions') now that I have this I try for x, y, z...
1
by: Benny | last post by:
Hi, I would like to know, if I need to do some floting point operations (mainly multiplication and division) on each roll of a table, should I read the data out from the DB and do the...
12
by: Jason | last post by:
Please don't laugh, this is my FIRST Python script where I haven't looked at the manual for help... import string import random class hiScores: hiScores=
1
by: Kevin | last post by:
Hi All Can someone tell me if I am doing this correctly, or can possibly suggest better ways, if I'm not doing this correctly. I have a windows application that I am writing,So I have a UI and...
27
by: Greg Smith | last post by:
Hello, I have been given a programming task that falls into the "impossible" category with my current skill set. I am hoping somebody out there knows how to do this and can save my b-t. I...
2
by: Josef Meile | last post by:
Hi, I have this constructor: public CExcelDatabase(string host, string user, string password, string database, bool promptCredentials, int findExcelInstance, bool readOnly) { //Some code...
0
by: Sin Jeong-hun | last post by:
I'm using Windows XP x64 edition, and I have just installed .NET Framework 2.0 (x64). When I was doing nothing with my computer the hard disk started making noises and the LED was blinking. I used...
9
by: oddvark | last post by:
Hello, under vc7.1 this code compiles: if (!parent.fillTool) parent.fillTool.dispose; where dispose is a method of fillTool. Notice that dispose does not have ( ) behind it. Under vc8,...
6
by: r035198x | last post by:
I have put together this article to give people starting Swing an awareness of issues that need to be considered when creating a Swing application. Most of the Swing tutorials that I have seen just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.