我必须将我以前的独立项目变成一个 Web 应用程序。在大多数情况下,一切正常,但我的柜台不是。用户可以选择查看他们得到正确和不正确的答案。我从原始项目中复制了大部分代码,除了几个 tweeks... idk 我做错了什么。
当您输入正确答案时,没有任何显示,但是当您输入错误答案时,它显示正确:0 不正确:1 并且它不会改变。我尝试使 numCorrect 和 numIncorrect 等于 0,如下所示......仍然没有。
任何帮助将不胜感激!
Protected Sub CheckButton_Click(sender As Object, e As EventArgs) Handles CheckButton.Click
'assign numbers to variable for calculation
Dim correctAnswer As Integer
Dim numCorrect As Integer = 0
Dim numIncorrect As Integer = 0
num1 = CInt(Val(FirstNumLabel.Text))
num2 = CInt(Val(SecondNumLabel.Text))
answerNum = CInt(Val(AnswerTextBox.Text))
'calculate the correct answer
Select Case OperationsRadioButtonList.SelectedIndex = 0
Case True
'addition operation
correctAnswer = num1 + num2
Case False
'subtraction operation
correctAnswer = num1 - num2
End Select
'tell user if their input is correct or incorrect
'show images and messages when answer is correct
If answerNum = correctAnswer Then
MessageLabel.Text = "Nice Job!"
HFaceImage.Visible = True
SFaceImage.Visible = False
'add count for numbers correct to summary
numCorrect += 1
'clear textbox for new input and focus to textbox for new
With AnswerTextBox
.Text = ""
.Focus()
End With
'generate new random set
Call RandomNumberGenerator()
Else 'show image and message if answer is incorrect
SFaceImage.Visible = True
HFaceImage.Visible = False
'add count for numbers incorrect to summary
numIncorrect = numIncorrect + 1 '
'display message if incorrect answer was given
MessageLabel.Text = "Try Again!"
'clear textbox for new input and focus to textbox
With AnswerTextBox
.Text = ""
.Focus()
End With
'show the number of correct and incorrect input when summaryCheckBox is checked
If CheckBox.Checked Then
CorrectCounterTextBox.Text = CStr(Val(numCorrect))
IncorrectCounterTextBox.Text = CStr(Val(numIncorrect))
Else
CorrectCounterTextBox.Text = ""
IncorrectCounterTextBox.Text = ""
End If
End If
End Sub