|
|
 |
| VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1). |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

July 5th, 2005, 10:18 AM
|
|
Authorized User
|
|
Join Date: Jan 2005
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
incrementing value of a variable
I am seeking advice on how I can change the code below to increment the value of a variable I called "sum.
On my form, I have the following:
- a simple combo box where user can select from a list
- a txt box where user can enter in a quantity
- a list box to list out the total of each item selected
- a txt box to display the sum
My problem is the txt box to display the grand total. I am having a hard time keeping track of the grand total. My program only display the total for the latest item selected.
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim sum As Double = 0
Dim list As String
Dim total2, totalsp, totalfat, totalipt, totalmfp, totalrb, total2cb, totalicb, totalgcb, totalmfpg As Double
list = cbo.Text
Select Case list
Case "Type 2 Curr. Guide", "Insulin Curr. Guide", "Gestational Curr. Guide "
total2 = CDbl(qtytxt.Text) * 90
ListBox1.Items.Add(total2)
Case "Success Plan"
totalsp = CDbl(qtytxt.Text) * 5.5
ListBox1.Items.Add(totalsp)
Case "Food & Activity Tablet"
totalfat = CDbl(qtytxt.Text) * 7.95
ListBox1.Items.Add(totalfat)
Case "Insulin Plan Tablet"
totalipt = CDbl(qtytxt.Text) * 7.95
ListBox1.Items.Add(totalipt)
Case "My Food Plan "
If CDbl(qtytxt.Text) >= 10 And CDbl(qtytxt.Text) <= 99 Then
totalmfp = CDbl(qtytxt.Text) * 1.3
ListBox1.Items.Add(totalmfp)
End If
If CDbl(qtytxt.Text) >= 100 And CDbl(qtytxt.Text) <= 499 Then
totalmfp = CDbl(qtytxt.Text) * 1.15
ListBox1.Items.Add(totalmfp)
End If
If CDbl(qtytxt.Text) >= 500 Then
totalmfp = CDbl(qtytxt.Text) * 1
ListBox1.Items.Add(totalmfp)
End If
Case "My Food Plan for GDM"
If CDbl(qtytxt.Text) >= 10 And CDbl(qtytxt.Text) <= 99 Then
totalmfpg = CDbl(qtytxt.Text) * 1.3
ListBox1.Items.Add(totalmfpg)
End If
If CDbl(qtytxt.Text) >= 100 And CDbl(qtytxt.Text) <= 499 Then
totalmfpg = CDbl(qtytxt.Text) * 1.15
ListBox1.Items.Add(totalmfpg)
End If
If CDbl(qtytxt.Text) >= 500 Then
totalmfpg = CDbl(qtytxt.Text) * 1
ListBox1.Items.Add(totalmfpg)
End If
Case ("Record Book")
If CDbl(qtytxt.Text) >= 1 And CDbl(qtytxt.Text) <= 9 Then
totalrb = CDbl(qtytxt.Text) * 1.5
ListBox1.Items.Add(totalrb)
End If
If CDbl(qtytxt.Text) >= 10 And CDbl(qtytxt.Text) <= 99 Then
totalrb = CDbl(qtytxt.Text) * 1.35
ListBox1.Items.Add(totalrb)
End If
If CDbl(qtytxt.Text) >= 100 Then
totalrb = CDbl(qtytxt.Text) * 1.2
ListBox1.Items.Add(totalrb)
End If
Case ("Type 2 Client Book")
If CDbl(qtytxt.Text) >= 1 And CDbl(qtytxt.Text) <= 9 Then
total2cb = CDbl(qtytxt.Text) * 7.95
ListBox1.Items.Add(total2cb)
End If
If CDbl(qtytxt.Text) >= 10 And CDbl(qtytxt.Text) <= 99 Then
total2cb = CDbl(qtytxt.Text) * 7.15
ListBox1.Items.Add(total2cb)
End If
If CDbl(qtytxt.Text) >= 100 Then
total2cb = CDbl(qtytxt.Text) * 6.35
ListBox1.Items.Add(total2cb)
End If
Case ("Insulin Client Book")
If CDbl(qtytxt.Text) >= 1 And CDbl(qtytxt.Text) <= 9 Then
totalicb = CDbl(qtytxt.Text) * 7.95
ListBox1.Items.Add(totalicb)
End If
If CDbl(qtytxt.Text) >= 10 And CDbl(qtytxt.Text) <= 99 Then
totalicb = CDbl(qtytxt.Text) * 7.15
ListBox1.Items.Add(totalicb)
End If
If CDbl(qtytxt.Text) >= 100 Then
totalicb = CDbl(qtytxt.Text) * 6.35
ListBox1.Items.Add(totalicb)
End If
Case ("Gestational Client Books")
If CDbl(qtytxt.Text) >= 1 And CDbl(qtytxt.Text) <= 9 Then
totalgcb = CDbl(qtytxt.Text) * 7.95
ListBox1.Items.Add(totalgcb)
End If
If CDbl(qtytxt.Text) >= 10 And CDbl(qtytxt.Text) <= 99 Then
totalgcb = CDbl(qtytxt.Text) * 7.15
ListBox1.Items.Add(totalgcb)
End If
If CDbl(qtytxt.Text) >= 100 Then
totalgcb = CDbl(qtytxt.Text) * 6.35
ListBox1.Items.Add(totalgcb)
End If
End Select
sum = total2 + totalsp + totalfat + totalipt + totalmfp + totalrb + total2cb + totalicb + totalgcb + totalmfpg
pricelst1.Text = CStr(sum)
End Sub
|

July 5th, 2005, 10:26 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,000
Thanks: 5
Thanked 37 Times in 36 Posts
|
|
hi there..
for wich i can see.. you are always sum only 1 item, the one you select in the combo.. you want to sum the listed elements???
you can sum the total from the text box in the last statemnet to get it better...
Code:
sum = total2 + totalsp + totalfat + totalipt + totalmfp + totalrb + total2cb + totalicb + totalgcb + totalmfpg + txtgrandtotal.text
HTH
Gonzalo
|

July 5th, 2005, 11:25 AM
|
|
Authorized User
|
|
Join Date: Jan 2005
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Thanks for the info. Yes, i am trying to get the list total. I tried your suggestions but it did not quite work. Is there any other way to sum the list? Thanks.
|

July 5th, 2005, 11:33 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,000
Thanks: 5
Thanked 37 Times in 36 Posts
|
|
ok.. what's the problem now??
just add the textbox that has the sum to the moment to the big sum..
your logic only sum the last item, the other are lost because you are not keeping the big total anywhere!
HTH
Gonzalo
|

July 5th, 2005, 01:04 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I appreciate all your help. Please bear with me, this is my 2nd VB.Net program so I am still not sure of my code.
You are right in stating that I am only summing 1 number. I think my problem is that I never get to the "grand total". I used your suggestion but I am erring our because first pass through the program, the txt box containing the sum is empty and VB.Net does not like a "" field.
I just want to add all the value in the listbox together to get a sum. Is there any other way to do this? thanks for your advice.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |