2015-07-11 31 views
-1

我在所有表格中都有此代碼,所以我可以在測驗中獲得總分。但是當得分表最終顯示出來時,它顯示0,並且當我有賴特或錯誤答案時更可能不增加。我很抱歉,我第一次在VB基礎知識。希望有人能幫助。總和不會在視覺基礎上增加2013

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 
+1

什麼是'Score'?表單?一類?一個文本框?還打開選項嚴格 – Plutonix

+0

如果您使用[Option Strict On](https://msdn.microsoft.com/en-us/library/zcd4xwzs.aspx),它可能會指出足夠的問題以便您修復代碼。附:它是Visual Basic,帶有大寫字母和複數形式。 –

回答

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 

現在您的窗口2並form3課程你需要一個事件,你需要在問題得到解答時提出事件。

Public Class Form2 
    Public event QuestionAnswered() 
    Property AnsweredCorrectly as integer = False 
    Sub RunThisAfterYouHaveIndicatedWhetherOrNotTheAnswerWasCorrect() 
    RaiseEvent QuestionAnswered() 
    End Sub 
end class 

我們解釋 你試圖調用一個普通類類型的內部常規和預期的結果,該類的活動實例內進行更新。或者看起來如此。

您必須對您嘗試更新的類的實例有某種引用。

在此示例中,您嘗試更新的類具有對需要信息的表單的引用。它通過等待表單提交事件並處理業務來接收信息。

+0

我也會向你推薦一個非常好的/便宜的網站,通過視頻導師教你如此之多。 LearnVB.net絕對令人驚歎,並且教你如此多,以至於你不知道你需要學習。 – ThatGuy

0

是選項2複選框?如果是這樣,我認爲你需要使用複選框的.checkstatus屬性,而不是.checked

If Option2.checkedstate = checkedstate.checked then