Attribute VB_Name = "Module1"
Option Explicit

Dim RomNumber As Integer
Dim comp1 As String
Dim comp2 As String

Public Function RomanToDecimal(Roman As String) As String
    Dim conv(7) As Variant
    Dim arabic As Integer, state As Integer, length As Integer, i As Integer, sidx As Integer
    conv(0) = "I,1"
    conv(1) = "V,5"
    conv(2) = "X,10"
    conv(3) = "L,50"
    conv(4) = "C,100"
    conv(5) = "D,500"
    conv(6) = "M,1000"
    conv(7) = "0,0"
    length = Len(Roman)
    state = 0


    Do While length >= 0
        i = 0
        sidx = length
        RomNumber = CInt(Mid(conv(i), InStr(1, conv(i), ",") + 1, Len(conv(i)) - InStr(1, conv(i), ",")))


        Do While RomNumber > 0
            comp1 = (Right(Left(Roman, sidx), 1))
            comp2 = Left(conv(i), 1)


            If (LCase(comp1)) = CStr(LCase(comp2)) Then


                If state > RomNumber Then
                    arabic = arabic - RomNumber
                Else
                    arabic = arabic + RomNumber
                    state = RomNumber
                End If
            End If
            i = i + 1
            If i = 8 Then GoTo ending:
            RomNumber = CInt(Mid(conv(i), InStr(1, conv(i), ",") + 1, Len(conv(i)) - InStr(1, conv(i), ",")))
        Loop
        length = length - 1
    Loop
ending:
    RomanToDecimal = arabic
End Function
