我有各种形式的代码,所以我可以在测验中得到一笔得分。但是当得分表最终显示时,它显示0并且当我有一个怀特或错误答案时更可能不会递增。对不起,这是我第一次使用VB基础知识。希望有人可以提供帮助。
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles NextButton1.Click
If Option2.Checked Then
Score.ScoreRight.Text = Score.ScoreRight.Text + 1
Dim Form2 As New Form3
Form3.Show()
Me.Hide()
Else
Score.ScoreWrong.Text = Score.ScoreWrong.Text + 1
Dim Form2 As New Form3
Form3.Show()
Me.Hide()
End If
End Sub
End Class
答案 0 :(得分:0)
我假设分数是一种形式,而Score.Scoreright和score.scorewrong是该形式的文本框
试试这个
Public class Score
Dim withevents Form2instance as new Form2
Dim withevents Form3instance as new Form3
Dim rightAnsweres as integer = 0
Dim wronganswers as integer = 0
Public sub Updateresults()
Scoreright.text = rightansweres
ScoreWrong.text = wronganswers
End Sub
Public sub Form2Instance_QuestionAnswered()Handles Form2Instance.QuestionAnswered
if Form2Instance.AnsweredCorrectly = true then
rightansweres = rightansweres+1
else
wronganswers = wronganswers + 1
end if
Form2instance.Hide
UpdateResults()
Form3instance.show
end sub
end class
现在,在form2和form3课程中,您需要一个事件,并且您需要在问题得到解答时提出事件。
Public Class Form2
Public event QuestionAnswered()
Property AnsweredCorrectly as integer = False
Sub RunThisAfterYouHaveIndicatedWhetherOrNotTheAnswerWasCorrect()
RaiseEvent QuestionAnswered()
End Sub
end class
现在解释一下 您正在尝试在通用类类型中调用例程,并期望在该类的活动实例内更新结果。或者看起来如此。
您必须对您尝试更新的类的实例有某种引用。
在此示例中,您尝试更新的类具有对其需要信息的表单的引用。它通过等待表单提出事件然后处理它的业务来接收信息。
答案 1 :(得分:0)
Option2是复选框吗?如果是这样,我认为您需要使用复选框的.checkstatus属性而不是.checked
If Option2.checkedstate = checkedstate.checked then