Reputation: 1
I am creating a roman numberal converter. I can not seem to get the program to function properly as I am getting the expression expected error. I have fixed most of these but the last two are eluding me. Please help to figuare this out. I am using Visual Basic 2013. Here is the code that I have so far.
'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
Upvotes: 0
Views: 661
Reputation: 6979
The Expression Expected
error is due to the extra comma at the end of your first IF statement.
If Integer.TryParse (txtUserInput.Text, CInt(intUserNumber), <-- this comma
There are other errors too in your code. e.g. your 2nd IF statement is missing the condition and the THEN keyword etc. You also have a lot of unnecessary conversions from String to Integer and vice-versa.
But coming back to your program, you don't need that long series of SELECT CASE
statements at all. That can be done in one line using the Choose
function, like this:
'Get the input from the user and test to see it is an integer.
If Integer.TryParse(txtUserInput.Text, intUserNumber) Then
'Display the Roman Numeral.
Select Case intUserNumber
Case 1 To 10
lblRomanNumeral.Text = Choose(intUserNumber, "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X").ToString
Case Else
lblRomanNumeral.Text = "integer value out of range!"
End Select
Else
lblRomanNumeral.Text = "Not an integer"
End If
HTH.
Upvotes: 1