任何人都知道如何正确地将数字转换为罗马数字?

时间:2015-03-24 02:55:09

标签: user-interface

Private Sub GoButton_Click(sender As Object, e As EventArgs) Handles GoButton.Click
    'turn number into roman numeral
    Dim userInput As Integer 'user's number
    Dim romanNum As String 'number converted into roman numeral

    Try
        userInput = Integer.Parse(NumberTextBox.Text)
        romanNum = getRomanNumeral(userInput)
        RomanLabel.Text = romanNum

    Catch ex As Exception
        MessageBox.Show("must enter a number, please try again")
    End Try

End Sub
Function getRomanNumeral(number As Integer) As String
    Dim answer As String 'the roman numeral or error if not valid
    Select Case number
        Case 1 : answer = "I"
        Case 2 : answer = "II"
        Case 3 : answer = "III"
        Case 4 : answer = "IV"
        Case 5 : answer = "V"
        Case 6 : answer = "VI"
        Case 7 : answer = "VII"
        Case 8 : answer = "VIII"
        Case 9 : answer = "IX"
        Case 10 : answer = "X"
        Case 20 : answer = "XX"
        Case 30 : answer = "XXX"
        Case 40 : answer = "XL"
        Case 50 : answer = "L"
        Case 60 : answer = "LX"
        Case 70 : answer = "LXX"
        Case 80 : answer = "LXXX"
        Case 90 : answer = "XC"
        Case 100 : answer = "C"


    End Select
    Return answer
End Function

0 个答案:

没有答案