473,406 Members | 2,352 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,406 software developers and data experts.

Checkboxes...I need a push in the right direction.

Hello everyone I am new to learning coding in general and am looking for something that will help me with check boxes. I am working with the VB coding language as presented in Visual Studio 2010 Ultimate.

I want to know if it is possible to create certain events if a certain amount of check boxes are checked? There are 10 check boxes I want to do this with.

Basically this is what I am trying to do...

If ONLY ONE check box is checked, REGARDLESS of which one it is, I want a message to pop up.

If two check boxes are checked REGARDLESS of which ones they are a different message pops up BUT it ignores completing the first action if only one check box were checked.

Essentially I am trying to avoid the situation presented in this video http://howtostartprogramming.com/vb-...and-check-box/ where checking all of the boxes will produce multiple check boxes. I only want one message to pop up regardless of how many check boxes are checked, but I want a different message based on how many check boxes are checked.

I know the following isn't the coding required, but it may explain things a little better than I could?

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4. EVENT A is this happening
  5. EVENT B is this happening
  6. EVENT C is this happening
  7. SOLUTION A is this
  8. SOLUTION B is this
  9. SOLUTION C is this
  10.  
  11. IF "event a" THEN "solution a"  
  12. END IF
  13.  
  14. IF "event b" THEN "solution b"
  15.     ELSE
  16.        ignore "event a" and "solution a" 
  17. END IF
  18.  
  19. IF "event c" THEN "solution c" 
  20.     ELSE
  21.        ignore "event a" and "solution a" 
  22.     ELSE
  23.        ignore "event b" and "solution b" 
  24. END IF
  25.  
  26. So I'm thinking some kind of counter is needed?
  27.  
Jun 26 '14 #1
1 1024
Luk3r
300 256MB
You could do something like what I've posted below. Hope it helps. All the checkBox events use the same action and the checked boxes are counted. Pretty straight forward:
Expand|Select|Wrap|Line Numbers
  1.     Private Sub CheckBoxAction()
  2.         Dim checkCount As Integer = 0
  3.  
  4.         For Each checkedBox As CheckBox In Controls
  5.             If checkedBox.Checked = True Then
  6.                 checkCount = checkCount + 1
  7.             End If
  8.         Next
  9.  
  10.         If checkCount = 1 Then
  11.             MsgBox("1")
  12.         ElseIf checkCount = 2 Then
  13.             MsgBox("2")
  14.         ElseIf checkCount = 3 Then
  15.             MsgBox("3")
  16.         ElseIf checkCount = 4 Then
  17.             MsgBox("4")
  18.         ElseIf checkCount = 5 Then
  19.             MsgBox("5")
  20.         End If
  21.     End Sub
  22.  
  23.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
  24.         CheckBoxAction()
  25.     End Sub
  26.  
  27.     Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
  28.         CheckBoxAction()
  29.     End Sub
  30.  
  31.     Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
  32.         CheckBoxAction()
  33.     End Sub
  34.  
  35.     Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged
  36.         CheckBoxAction()
  37.     End Sub
  38.  
  39.     Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged
  40.         CheckBoxAction()
  41.     End Sub
Jun 29 '14 #2

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

Similar topics

3
by: MooMaster | last post by:
I'm a complete beginner in Python, but I've been fooling around with Java for a couple years, so I have decent programming experience... Anyway, I was sitting around playing with Python, when I...
5
by: Joseph Ellis | last post by:
Hello all. I have a family website that I have been maintaining for the past year and a half or so. It includes a photo album that has grown quite large. So far I've displayed the photo album...
1
by: A. Name | last post by:
Can someone please point me in the right direction? This is what I want to accomplish. The page has a simple form for input on it. When a user enters in information and clicks the button, the...
4
by: John Osborne | last post by:
I'm a beginner at this programming thing (C# and VB/VB.Net) but I have been given a task that I don't even knwo how to start to accomplish. I'm not asking anyone to write the code or anything,...
4
by: kcmagg | last post by:
Mornin, group. Long-time usenet lurker, 1st time poster to this group. If I am in the wrong ballpark, please point me in the right direction :-) I work in a call center and what we are looking...
5
by: Jay Pondy | last post by:
Given these two virtual paths http://mysite.com/ABCCompany/SomePage.aspx http://mysite.com/XYZCompany/SomePage.aspx Is there any way in ASP.Net 2.0 to parse out the 'ABCCompany' and...
0
by: =?Utf-8?B?Rmxhc2hNZXJsb3Q=?= | last post by:
We use .NET but we do NOT have Exchange. Ok, we have this enterprise application. The app currently sends emails from 15 different places in the code with no feedback, no monitoring, just push...
5
by: AManAfterGod | last post by:
OK, I'm fairly new to Java and I wanted to try if I could convert an easy Microsoft Excel problem into Java but I've hit a road block. I was wondering if one of you could point me in the right...
2
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i have an excel file that contains employee information. inside the workbook there are numerous worksheets - one per employee. is it possible to iterate thru the workbook reading pieces...
6
by: chloejacobs | last post by:
Hi every1! My first post on Bytes :) I want to create a simple web page that will read of CSV file, sort the file by certain fields, take out duplicate entries if 3 fields have the same value...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.