|
-
Feb 8th, 2002, 12:30 PM
#1
Thread Starter
Junior Member
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
-
Feb 8th, 2002, 12:31 PM
#2
Retired VBF Adm1nistrator
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]
-
Feb 8th, 2002, 12:33 PM
#3
Lively Member
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.
-
Feb 8th, 2002, 12:33 PM
#4
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
-
Feb 8th, 2002, 12:39 PM
#5
Thread Starter
Junior Member
Doesn't seem to work
I don't know what's wrong with the code.......I entered the text just like you said.
-
Feb 8th, 2002, 12:44 PM
#6
Lively Member
VB Code:
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
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.
-
Feb 8th, 2002, 12:56 PM
#7
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|