User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 427,376 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,988 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 578 | Replies: 1
Reply
Join Date: Mar 2008
Posts: 8
Reputation: djinn1971 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
djinn1971 djinn1971 is offline Offline
Newbie Poster

check box problem

  #1  
Mar 22nd, 2008
i have 3 check boxes then you check each indivual box the amount shows up in the appropiate label. but if you check more that one it will not add the values together does anyone have any idea how to the checkbox values to add together when more that one box is selected?/ here are the check box code:


  1. Private Sub GolfCheckBox_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GolfCheckBox.Click
  2. If Me.GolfCheckBox.Checked = True Then
  3. mintAdditional = 25
  4. End If
  5. Me.AdditionalLabel.Text = Format(mintAdditional, "currency")
  6. End Sub
  7.  
  8. Private Sub RacquetballCheckBox_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RacquetballCheckBox.Click
  9. If Me.RacquetballCheckBox.Checked = True Then
  10. mintAdditional = 20
  11. End If
  12. Me.AdditionalLabel.Text = Format(mintAdditional, "currency")
  13. End Sub
  14.  
  15. Private Sub TennisCheckBox_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TennisCheckBox.Click
  16. If Me.TennisCheckBox.Checked = True Then
  17. mintAdditional = 30
  18. End If
  19. Me.AdditionalLabel.Text = Format(mintAdditional, "currency")
  20. End Sub
  21.  
  22. Private Sub CalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CalcButton.Click
  23. Dim intBasic As Integer
  24. Dim sngTotal As Single
  25. intBasic = Val(Me.BasicTextBox.Text)
  26. Select Case True
  27. Case Me.TennisCheckBox.Checked = True
  28. sngTotal = intBasic + mintAdditional
  29. Case Me.RacquetballCheckBox.Checked = True
  30. sngTotal = intBasic + mintAdditional
  31. Case Me.GolfCheckBox.Checked = True
  32. sngTotal = intBasic + mintAdditional
  33. End Select
  34. Me.TotalLabel.Text = Format(sngTotal, "currency")
  35. Me.AdditionalLabel.Text = Format(mintAdditional, "currency")
  36. End Sub
Last edited by WolfPack : Mar 22nd, 2008 at 11:53 am. Reason: Added code tags. Use them when you post code.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2008
Location: Wales
Posts: 30
Reputation: BluePaper is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
BluePaper's Avatar
BluePaper BluePaper is offline Offline
Light Poster

Re: check box problem

  #2  
Mar 22nd, 2008
Mhm. Well I found it hard to follow your code and what exactly it does. But if I read correctly at the beginning you want to do the following:

  1.  
  2. Public Class Learning2
  3.  
  4. Dim total As Double = 0
  5. Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
  6. If CheckBox1.Checked = True Then
  7. total = total + 30
  8. ElseIf CheckBox1.Checked = False And total <> 0 Then
  9. total = total - 30
  10. End If
  11. Label1.Text = FormatCurrency(total)
  12. End Sub
  13.  
  14. Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
  15. If CheckBox2.Checked = True Then
  16. total = total + 15
  17. ElseIf CheckBox2.Checked = False And total <> 0 Then
  18. total = total - 15
  19. End If
  20. Label1.Text = FormatCurrency(total)
  21. End Sub
  22.  
  23. Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
  24. If CheckBox3.Checked = True Then
  25. total = total + 25
  26. ElseIf CheckBox3.Checked = False And total <> 0 Then
  27. total = total - 25
  28. End If
  29. Label1.Text = FormatCurrency(total)
  30. End Sub
  31.  
  32. Private Sub Learning2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  33. Label1.Text = FormatCurrency(total)
  34. End Sub
  35. End Class

I've little or no idea how to help you with your code though sorry as I find it hard to debug others code.

By the looks of things though you just keep on replacing the sngTotal instead of adding things on.

Just ask if you need any more help

EDIT: Oh yeh, all my checkbox names are default and the prices are just test numbers, so just change as you need
Last edited by BluePaper : Mar 22nd, 2008 at 11:20 am.
Stone In Focus - Caffeine Group - CoffeePHP - Open Notes - Onyx - Redpoint Network - Espresso
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 3:57 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC