Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 11th, 2008, 09:09 PM
JSClark JSClark is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Amherst, MA, USA
Posts: 271 JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 5 h 49 m 46 sec
Reputation Power: 19
Interesting Survey Program, Can't See Bug...

So I've been working on some programming using Visual Basic, and have had no problems with debugging and testing small programs, except for this one.

First off, the code:
Code:
Public Class SiblingSurveyForm
   ' display what siblings user selects
   Private Sub submitButton_Click(ByVal sender As _
      System.Object, ByVal e As System.EventArgs) _
      Handles submitButton.Click

      ' check if user selects brothers or sisters
      ' and no siblings
        If (noneCheckBox.Checked = True AndAlso _
        brotherCheckBox.Checked = True AndAlso _
        sisterCheckBox.Checked = True) Then
            MessageBox.Show("Selected combination is not possible", _
               "Invalid Input", MessageBoxButtons.OK, _
               MessageBoxIcon.Exclamation)

            ' check if user selects brothers and no siblings
        ElseIf brotherCheckBox.Checked = True AndAlso _
        noneCheckBox.Checked = True Then
            MessageBox.Show("Selected combination is not possible", _
            "Invalid Input", MessageBoxButtons.OK, _
            MessageBoxIcon.Exclamation)

            ' check if user selects sisters and no siblings
        ElseIf sisterCheckBox.Checked = True AndAlso _
        noneCheckBox.Checked = True Then
            MessageBox.Show("Selected combination is not possible", _
            "Invalid Input", MessageBoxButtons.OK, _
            MessageBoxIcon.Exclamation)

            ' check if user has brothers and sisters
        ElseIf brotherCheckBox.Checked = True OrElse _
           sisterCheckBox.Checked = True AndAlso _
           noneCheckBox.Checked = False Then
            MessageBox.Show("You have brothers and sisters", _
               "Siblings", MessageBoxButtons.OK, _
               MessageBoxIcon.Information)

            ' check if user has brothers
        ElseIf brotherCheckBox.Checked = True AndAlso _
        sisterCheckBox.Checked = False AndAlso _
        noneCheckBox.Checked = False Then
            MessageBox.Show("You have at least one brother", _
               "Siblings", MessageBoxButtons.OK, _
               MessageBoxIcon.Information)

            ' check if user has sisters
        ElseIf sisterCheckBox.Checked = True AndAlso _
        brotherCheckBox.Checked = False AndAlso _
        noneCheckBox.Checked = False Then
            MessageBox.Show("You have at least one sister", _
               "Siblings", MessageBoxButtons.OK, _
               MessageBoxIcon.Information)

            ' user has no siblings
        Else
            MessageBox.Show("You have no siblings", _
               "Siblings", MessageBoxButtons.OK, _
               MessageBoxIcon.Information)
        End If
   End Sub ' submitButton_Click
End Class ' SiblingSurveyForm


The program is to determine, based upon CheckBoxes, if the user has at least one brother, or a sister, or a combination of both. The program is to also generate an error to the user if either the Brother / Sister CheckBoxes are checked, along with the No Siblings CheckBox. Those work fine.

My issue is, when just Brother or Sister are selected, the program is to generate a message saying that the user at least has one brother or sister... the message appears saying that the user has both brothers and sisters.

Does anyone see an issue with the code that I can't see? I have tried various logical operators to see if I can have the program test for the right result, based upon what CheckBox is checked or not.

Thanks!
__________________
-Jason Clark

Reply With Quote
  #2  
Old August 11th, 2008, 09:27 PM
medialint's Avatar
medialint medialint is offline
Type Cast Exception
Click here for more information.
 
Join Date: Apr 2004
Location: Tralfamadore
Posts: 13,653 medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)  Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 2 Weeks 2 Days 4 h 51 m 35 sec
Reputation Power: 4390
Facebook
Quote:
My issue is, when just Brother or Sister are selected, the program is to generate a message saying that the user at least has one brother or sister... the message appears saying that the user has both brothers and sisters.


I think you should check out the short circuiting you got going on for one thing.

You probably want the old fashioned

If (((Brother) Or (Sister)) And Not (None))

You can stop testing for None with that

Code:
If (((Brother) Or (Sister)) And Not (None)) Then
  If (Brother) Then
    If (Sister) Then
      ' You have both
    Else
      ' You have brother
    EndIf
  Else
    ' You have sister
  EndIf
Else
  ' Not valid
EndIf
__________________
medialint.com


"Beware of the man who works hard to learn something, learns it, and finds himself no wiser than before. He is full of murderous resentment of people who are ignorant without having come by their ignorance the hard way."
- Vonnegut - Cat's Cradle, 1963

Reply With Quote
  #3  
Old August 11th, 2008, 09:35 PM
JSClark JSClark is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Amherst, MA, USA
Posts: 271 JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 5 h 49 m 46 sec
Reputation Power: 19
So in other words, shortening the If... ElseIf statements I have will display my results more accurately?

I'll give it a shot and report back.

Reply With Quote
  #4  
Old August 11th, 2008, 11:40 PM
JSClark JSClark is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Amherst, MA, USA
Posts: 271 JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 5 h 49 m 46 sec
Reputation Power: 19
And fixed.

There was a logical operator in the "brothers and sisters" section of the ElseIf statements that was throwing the program off. Changed the "OrElse" entry to an "AndAlso", and it runs exactly how I want it.

Medialint, I did try the suggestion you had, and I'm not sure if it was just the way I was coding things, but I was getting errors left and right, and still was not working the way I wanted it to. If you want to explain it further, I would be willing to see the logic you had thought of behind your suggestion though.

Reply With Quote
  #5  
Old August 12th, 2008, 10:09 AM
medialint's Avatar
medialint medialint is offline
Type Cast Exception
Click here for more information.
 
Join Date: Apr 2004
Location: Tralfamadore
Posts: 13,653 medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)medialint User rank is General 51st Grade (Above 100000 Reputation Level)  Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 307430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 2 Weeks 2 Days 4 h 51 m 35 sec
Reputation Power: 4390
Facebook
That's mostly a pseudocode mockup I thought it should be fairly clear. You don't need to test for each of permutations.

Last edited by medialint : August 12th, 2008 at 10:11 AM.

Reply With Quote
  #6  
Old August 12th, 2008, 12:37 PM
JSClark JSClark is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Amherst, MA, USA
Posts: 271 JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level)JSClark User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 5 h 49 m 46 sec
Reputation Power: 19
Quote:
Originally Posted by medialint
That's mostly a pseudocode mockup I thought it should be fairly clear. You don't need to test for each of permutations.


I'll give it another shot when I have the chance.

Reply With Quote
  #7  
Old August 12th, 2008, 01:57 PM
LyonHaert's Avatar
LyonHaert LyonHaert is offline
Arcane Scribbler
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2005
Location: Indianapolis, IN
Posts: 1,886 LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 1 m 51 sec
Reputation Power: 557
You might want to consider the non-short-circuiting versions And and Or instead of the short-circuiting versions AndAlso and OrElse. When using the short-circuiting, you have to be a little more careful with the order in which conditions are checked so that short-circuiting doesn't skip something (such as checking the value of the 'none' checkbox) that it shouldn't ever skip.

When you have X Or Y, both X and Y will be evaluated. When you have X OrElse Y, then first X is evaluated. If it is True, then it doesn't matter whether Y evaluates to True or False, so it doesn't look at Y; it short-circuits and evaluates as True.

When you have X And Y, both X and Y will be evaluated. When you have X AndAlso Y, then first X is evaluated. If it is False, then it doesn't matter whether Y evaluates to True or False, so it doesn't look at Y; it short-circuits as False.
__________________
Joel B Fant
"An element of conflict in any discussion is a very good thing. Shows everybody's taking part, nobody left out. I like that."

.NET Must-Haves
Tools: Reflector
References: Threading in .NET

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Interesting Survey Program, Can't See Bug...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT