我正在製作一個小程序,用於檢查您輸入的最多4個數字,每個數字表示不同的數字。但我想讓它說「選擇一個數字」。當有人用字母代替時。基本上我的其他東西應該是隻有當答案中包含一個字母,但是當我運行該程序,並鍵入一個字母,然後按回車,我得到一個關於不能將答案轉換爲雙精度的錯誤,而且我已經到處尋找解決這個問題,但沒有接近。請幫助,我非常感謝它。我輸入了一個按下的輸入,這是我得到的錯誤(儘管它與所有字母不同)。錯誤是:{「從字符串轉換」「a」到類型'雙精度'無效。「 } If語句開始時發生錯誤。爲什麼我在將字母放入字符串時出現錯誤?
If (e.KeyCode = Keys.Enter) Then
Dim Answer As String
Answer = txtAnswer.Text
If Answer = 1 Then
txtResponse.Text = "Good"
ElseIf Answer = 2 Then
txtResponse.Text = "Good again"
ElseIf Answer = 3 Then
txtResponse.Text = "Not too good"
ElseIf Answer = 4 Then
txtResponse.Text = "Terrible"
ElseIf Answer > 4 Or Answer < 1 Then
txtResponse.Text = "Wrong Answer"
Else
txtResponse.Text = "pick a number"
End If
End If
1是一個數字,「1」是字符串。因此,無論您是將「Dim Answer As Integer」還是「Answer = CInt(txtAnswer.Text)」,或將所有IF塊更改爲「1」,「2」等,但不能使用「>」,「<」爲字符串。 – PatricK