Public Class Form1
    Dim values() As Integer = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}
    Dim numerals(,) As String = {{"M"}, {"CM"}, {"D"}, {"CD"}, {"C"}, {"XC"}, {"L"}, {"XL"}, {"X"}, {"IX"}, {"V"}, {"IV"}, {"I"}}
    Dim number As Integer
    Dim result As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        result = ""
        number = Val(RichTextBox1.Text)
        If number < 0 Or number > 3999 Then
            MsgBox("Numar negativ sau prea mare", 16)
            Exit Sub
        End If
        For i = 0 To 12
            While number >= values(i)
                number -= values(i)
                result = result & numerals(i, 0)
            End While
        Next
        RichTextBox2.Text = result
    End Sub

End Class
