2016-03-29 3 views
0

VB 2010で数学クイズに問題があります。間違った番号を入力すると、プログラムがクラッシュします。誰も助けることができます。私はエラーがなく視覚的に見えるようにコードを編集しましたが、現在は少し問題があります。おかげでここに私のコードは、Double数学クイズVB 2010奇数クラッシュ

The crash

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 

    If TextBox1.Text = String.Empty Then 
     MsgBox("Please type your asnswer :)") 
    ElseIf Not IsNumeric(TextBox1.Text) Then 
     MsgBox("This is not a valid number.", MsgBoxStyle.Critical) 
    End If 

    userAnswer = TextBox1.Text 

    If userAnswer = numZ Then 
     MsgBox("Correct. Proceed to the next question") 
     score = score + 1 
    Else 
     MsgBox("Sorry this answer is incorrect. THe correct answer is " + numZ) 
    End If 

    Turn2.Text = turn 
    turn = turn + 1 

    If turn < 10 Then 
     numA.Text = (num1.Next(1, 10)) 
     numB.Text = (num2.Next(1, 10)) 
     sim = (sim1.Next(1, 4)) 


     numX = numA.Text 
     numY = numB.Text 

     Select Case sim 
      Case 1 
       SimZ.Text = "+" 
       numZ = numX + numY 
      Case 2 
       SimZ.Text = "X" 
       numZ = numX * numY 
      Case 3 
       SimZ.Text = "-" 
       numZ = numX - numY 
     End Select 
    Else 
     MessageBox.Show("Your score is " + score + " out of ten") 
     Me.Close() 
    End If 



End Sub 

答えて

2

+だとVB.NetでStringは、文字列を数値に変換しようとします。ただ、numZToStringを呼び出して(と、それはファンキーな変換を行いませんので、連結のための&を使用)

エラーがclearly documented hereです。

+1

はい。私は、ここでユーザに何度も '+'演算子で文字列を連結しないように何回言いましたか分かりません。 :D –