Number To Romawi


Function Latin2Roman(number As Long) As String
Dim n As Long
Dim j As Integer, i As Integer
Dim Rom, Latin
Dim Romawi As String

Rom = Array(“i”, “iv”, “v”, “ix”, _
“x”, “xl”, “l”, “xc”, _
“c”, “cd”, “d”, “cm”, _
“m”)

Latin = Array(1, 4, 5, 9, _
10, 40, 50, 90, _
100, 400, 500, 900, _
1000)

Romawi = “”

For j = 12 To 0 Step -1
n = Int(number / Latin(j))
If n <> 0 Then
For i = 1 To n
Romawi = Romawi & Rom(j)
Next i
End If
number = number Mod Latin(j)
Next
Latin2Roman = Romawi

End Function

Function Roman2Latin(Romawi As String) As Long
Dim n As Long
Dim i As Integer
Dim Rom, Latin

Rom = Array(“i”, “1″, “v”, “2″, _
“x”, “3″, “l”, “4″, _
“c”, “5″, “d”, “6″, _
“m”)

Latin = Array(1, 4, 5, 9, _
10, 40, 50, 90, _
100, 400, 500, 900, _
1000)

Romawi = Replace(Romawi, “iv”, “1″)
Romawi = Replace(Romawi, “ix”, “2″)
Romawi = Replace(Romawi, “xl”, “3″)
Romawi = Replace(Romawi, “xc”, “4″)
Romawi = Replace(Romawi, “cd”, “5″)
Romawi = Replace(Romawi, “cm”, “6″)

n = 0
For i = 12 To 0 Step -1
While Rom(i) = Mid(Romawi, 1, 1) And Len(Romawi) > 0
n = n + Latin(i)
Romawi = Mid(Romawi, 2)
Wend
Next i
Roman2Latin = n
End Function

Private Sub Command1_Click()

End Sub

Private Sub cmdConvert_Click(Index As Integer)
If Index = 0 Then
If Val(txtNumber.Text) = 0 Then Exit Sub
txthasil.Text = Latin2Roman(Val(txtNumber.Text))
Else
txtLatin.Text = Roman2Latin(txtRom.Text)
End If
End Sub

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s