If strChoice = StrCapital, display CORRECT in the lblMsg
Else, display INCORRECT
8 Replies - 305 Views - Last Post: 22 February 2012 - 10:19 PM
#1
how do I make verify answer button click event show incorrect
Posted 22 February 2012 - 05:26 PM
Replies To: how do I make verify answer button click event show incorrect
#2
Re: how do I make verify answer button click event show incorrect
Posted 22 February 2012 - 06:01 PM
For the label you set it's Text property to the String you want.
If strChoice = strCapital Then lblMsg.Text = "Correct" Else lblMsg.Text = "Incorrect" End If
#3
Re: how do I make verify answer button click event show incorrect
Posted 22 February 2012 - 06:09 PM
That's exactly what i had but, it's giving me "CORRECT" everytime, even when it's wrong.
I apparently have something else wrong with the codes.
We're working with a form with 5 state radio buttons and 5 capital radio buttons.
This is only my 5th week in Visual Basics, so I'm working with trial and error.
Thanks for you input.....twarmath
I apparently have something else wrong with the codes.
We're working with a form with 5 state radio buttons and 5 capital radio buttons.
This is only my 5th week in Visual Basics, so I'm working with trial and error.
Thanks for you input.....twarmath
#4
Re: how do I make verify answer button click event show incorrect
Posted 22 February 2012 - 06:18 PM
What are you putting int strChoice and what are you putting into strCapital?
When comparing strings, they must be the same
For example
"Indiana" does not equal "Indianapolis"
Put a breakpoint on the line that starts the IF statement and when it stops, hover over strChoice and see what is there, then hover over strCapital and see what is there. These must be identical for that to show Correct
When comparing strings, they must be the same
For example
"Indiana" does not equal "Indianapolis"
Put a breakpoint on the line that starts the IF statement and when it stops, hover over strChoice and see what is there, then hover over strCapital and see what is there. These must be identical for that to show Correct
#5
Re: how do I make verify answer button click event show incorrect
Posted 22 February 2012 - 06:27 PM
You'll have to show us how you set that strChoice and strCapital variables and what their scope is.
#6
Re: how do I make verify answer button click event show incorrect
Posted 22 February 2012 - 07:10 PM
Am I allowed to attach my code as my reply? I'm not all together sure of the rules yet, since I just joined a couple of hours ago.
#7
Re: how do I make verify answer button click event show incorrect
Posted 22 February 2012 - 07:14 PM
Yes, it's best to limit it to the areas where the problem is occurring but there are times when more information is needed. Just make sure you hilight and press the code button to put it in a code window.
#8
Re: how do I make verify answer button click event show incorrect
Posted 22 February 2012 - 07:18 PM
(I know I'm missing something, but just can't see it yet!)
Public Class frmMain
Dim Capitals() As String = {"Little Rock", "Springfield", "Frankfort", "Salem", "Madison"}
Dim strCapital As String
Dim Choice() As String = {"Arkansas", "Illinois", "Kentucky", "Oregon", "Wisconsin"}
Dim strChoice As String
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' invoke click event for default buttons when form first appears on screen
radArkansas.PerformClick()
radFrankfort.PerformClick()
End Sub
Private Sub radArkansas_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles radArkansas.Click
' assign appropriate capital to the correct state radio button
If strCapital = "Little Rock" Then
lblMsg.Text = "Arkansas"
End If
End Sub
Private Sub radIllinois_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles radIllinois.Click
If strCapital = "Springfield" Then
lblMsg.Text = "Illinois"
End If
End Sub
Private Sub radKentucky_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles radKentucky.Click
If strCapital = "Frankfort" Then
lblMsg.Text = "Kentucky"
End If
End Sub
Private Sub radOregon_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles radOregon.Click
If strCapital = "Salem" Then
lblMsg.Text = "Oregon"
End If
End Sub
Private Sub radWisconsin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles radWisconsin.Click
If strCapital = "Madison" Then
strChoice = "Wisconsin"
End If
End Sub
Private Sub radFrankfort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles radFrankfort.Click
' assign appropriate state to the appropriate capital radio button
If strChoice = "Kentucky" Then
lblMsg.Text = "Frankfort"
End If
End Sub
Private Sub radLittleRock_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles radLittleRock.Click
If strChoice = "Arkansas" Then
lblMsg.Text = "Little Rock"
End If
End Sub
Private Sub radMadison_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles radMadison.Click
If strChoice = "Wisconsin" Then
lblMsg.Text = "Madison"
End If
End Sub
Private Sub radSalem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles radSalem.Click
If strChoice = "Oregon" Then
lblMsg.Text = "Salem"
End If
End Sub
Private Sub radSpringfield_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles radSpringfield.Click
If strChoice = "Illinois" Then
lblMsg.Text = "Springfield"
End If
End Sub
Private Sub btnVerify_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVerify.Click
If strChoice = strCapital Then
lblMsg.Text = "Correct"
Else
lblMsg.Text = "Incorrect"
End If
End Sub
End Class
This post has been edited by AdamSpeight2008: 23 February 2012 - 06:39 AM
Reason for edit:: What where you Missing? CODE TAGS for a start.
#9
Re: how do I make verify answer button click event show incorrect
Posted 22 February 2012 - 10:19 PM
For obvious reasons you cannot compare those string as they will never be equal - right? What you can do is evaluate each arrays elements for a match - since each element position is related to the other array element by it's position. I don't get the whole layout either.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|