Results 1 to 7 of 7

Thread: Can someone help me out?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    22

    Question Can someone help me out?

    I need to know what's wrong with this code:
    if I'm getting a correct answer when I select Wisconsin and Madison then why am I getting incorrect when I select other correct options?

    Private Sub cmdCheck_Click()
    If optCal.Value And optSac.Value = True Then
    lblMsg.Caption = "Correct"
    Else
    lblMsg.Caption = "Incorrect"
    End If

    If optCol.Value And optDen.Value = True Then
    lblMsg.Caption = "Correct"
    Else
    lblMsg.Caption = "Incorrect"
    End If

    If optIll.Value And optSpr.Value = True Then
    lblMsg.Caption = "Correct"
    Else
    lblMsg.Caption = "Incorrect"
    End If

    If optOre.Value And optSal.Value = True Then
    lblMsg.Caption = "Correct"
    Else
    lblMsg.Caption = "Incorrect"
    End If

    If optWis.Value And optMad.Value = True Then
    lblMsg.Caption = "Correct"
    Else
    lblMsg.Caption = "Incorrect"
    End If
    End Sub

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    The value property doesn't return a Boolean value.
    Use vbChecked and what not instead. That should fix the problem for you
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Lively Member nateobot's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Minnesota
    Posts
    71
    The code is running through all your if statements. The last if statement is to check for Wisconsin and Madison and if neither of those are checked you will get incorrect.

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    also ned to change these

    If optCal.Value And optSac.Value = True Then

    to like this

    If optCal.Value = vbChecked And optSac.Value = vbChecked Then
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    22

    Doesn't seem to work

    I don't know what's wrong with the code.......I entered the text just like you said.

  6. #6
    Lively Member nateobot's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Minnesota
    Posts
    71
    VB Code:
    1. Private Sub cmdCheck_Click()
    2. If optCal.Value And optSac.Value = True Then
    3. lblMsg.Caption = "Correct"
    4. Else
    5. lblMsg.Caption = "Incorrect"
    6. End If
    7.  
    8. If optCol.Value And optDen.Value = True Then
    9. lblMsg.Caption = "Correct"
    10. Else
    11. lblMsg.Caption = "Incorrect"
    12. End If
    13.  
    14. If optIll.Value And optSpr.Value = True Then
    15. lblMsg.Caption = "Correct"
    16. Else
    17. lblMsg.Caption = "Incorrect"
    18. End If
    19.  
    20. If optOre.Value And optSal.Value = True Then
    21. lblMsg.Caption = "Correct"
    22. Else
    23. lblMsg.Caption = "Incorrect"
    24. End If
    25.  
    26. If optWis.Value And optMad.Value = True Then
    27. lblMsg.Caption = "Correct"
    28. Else
    29. lblMsg.Caption = "Incorrect"
    30. End If
    31. End Sub

    That is your code. Here is what happens.

    I select California and Sacramento. It checks the first if statement. Tells me correct. Moves to the next 4 if statements and tells me i am incorrect. The ONLY time you will get and end result of Correct is with Madison and Wisconsin cause that is the last if statement that is checked by the application. I hope i explained that a little better.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    22

    This is the remainder

    This is in the General Declarations click event procedure:
    Dim strCapital as String, strChoice as State

    Then this is as follows in the respective option buttons code windows:

    Private Sub optCal_Click()
    'to define correct capital
    strCapital = "Sacramento"
    End Sub

    Private Sub optCol_Click()
    'to define correct capital
    strCapital = "Denver"
    End Sub

    Private Sub optDen_Click()
    'to define correct State
    strChoice = "Colorado"
    End Sub

    Private Sub optIll_Click()
    'to define correct capital
    strCapital = "Springfield"

    End Sub

    Private Sub optMad_Click()
    'to define correct state
    strChoice = "Wisconsin"
    End Sub

    Private Sub optOre_Click()
    'to define correct captial
    strCapital = "Salem"

    End Sub

    Private Sub optSac_Click()
    'to define correct state
    strChoice = "California"
    End Sub

    Private Sub optSal_Click()
    'to define correct state
    strChoice = "Oregon"
    End Sub

    Private Sub optSpr_Click()
    'to define correct state
    strChoice = "Illinois"
    End Sub

    Private Sub optWis_Click()
    'to define correct capital
    strCapital = "Madison"

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width