Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 5th, 2005, 09:18 AM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old July 5th, 2005, 09:26 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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
Reply With Quote
  #3 (permalink)  
Old July 5th, 2005, 10:25 AM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #4 (permalink)  
Old July 5th, 2005, 10:33 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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
Reply With Quote
  #5 (permalink)  
Old July 5th, 2005, 12:04 PM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Incrementing the variable value Swetha XSLT 2 April 28th, 2008 04:43 PM
Incrementing member variable in Synchronized block vikkiefd Pro Java 0 March 24th, 2008 04:15 AM
Way to incrementing value of variable in xsl vikkiefd XSLT 14 March 12th, 2008 10:33 PM
Incrementing numbers RubyRue ASP.NET 1.0 and 1.1 Basics 2 January 30th, 2008 12:16 AM
XSL Loop and incrementing a variable 2007-03-29 XSLT 8 March 30th, 2007 10:41 AM



All times are GMT -4. The time now is 01:58 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.