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),'?'末尾有一个逗号?这是造成'表达预期'错误。但是你的代码有更多的问题。例如你的第二中频缺少了条件,然后。 –