0
我正在創建一個羅馬數字轉換器。我似乎無法讓程序正常工作,因爲我收到表達式期望的錯誤。我已經修復了其中的大部分,但最後兩個都躲過了我。請幫忙解釋一下。我正在使用Visual Basic 2013.以下是我迄今爲止的代碼。表達式預計不知道我在哪裏出錯
'Get the input from the user and test to see it is an integer.
If Integer.TryParse (txtUserInput.Text, CInt(intUserNumber), Then
'Display the Roman Numeral.
Select Case (CStr(intUserNumber()))
Case CStr(1)
lblRomanNumeral.Text = "I"
Case CStr(2)
lblRomanNumeral.Text = "II"
Case CStr(3)
lblRomanNumeral.Text = "III"
Case CStr(4)
lblRomanNumeral.Text = "IV"
Case CStr(5)
lblRomanNumeral.Text = "V"
Case CStr(6)
lblRomanNumeral.Text = "VI"
Case CStr(7)
lblRomanNumeral.Text = "VII"
Case CStr(8)
lblRomanNumeral.Text = "VIII"
Case CStr(9)
lblRomanNumeral.Text = "IX"
Case CStr(10)
lblRomanNumeral.Text = "X"
End Select
If
lblRomanNumeral.Text = "Not an integer"
Else
End If
End
End Sub
有很多不必要的轉換...字符串到int回到字符串和Case語句的另一個字符串轉換。如果它是一個Int32變量,則不需要'CInt(intUserNumber)'。 – Plutonix
爲什麼在你的'CInt(intUserNumber),'?'末尾有一個逗號?這是造成'表達預期'錯誤。但是你的代碼有更多的問題。例如你的第二中頻缺少了條件,然後。 –