Anda di halaman 1dari 2

Dim Huruf(0 To 9) As String

Dim ax(0 To 3) As Double

Function INIT_angka()
Huruf(0) = ""
Huruf(1) = "Satu "
Huruf(2) = "Dua "
Huruf(3) = "Tiga "
Huruf(4) = "Empat "
Huruf(5) = "Lima "
Huruf(6) = "Enam "
Huruf(7) = "Tujuh "
Huruf(8) = "Delapan "
Huruf(9) = "Sembilan "

End Function

Function dgratus(angka As Double) As String


Temp = ""
INIT_angka
panjang = Len(Trim(Str(angka)))
nilai = Right("000", 3 - panjang) + Trim(Str(angka))
For y = 3 To 1 Step -1
ax(y) = Mid(nilai, y, 1)
Next y
Select Case ax(1)
Case Is = 1
Temp = "Seratus "
Case Is > 1
Temp = Huruf(Val(ax(1))) + "" + "Ratus "
Case Else
Temp = ""
End Select

Select Case ax(2)


Case Is = 0
Temp = Temp + Huruf(Val(ax(3)))
Case Is = 1
Select Case ax(3)
Case Is = 1
Temp = Temp + "Sebelas"
Case Is = 0
Temp = Temp + "Sepuluh"
Case Else
Temp = Temp + Huruf(Val(ax(3))) + " Belas"
End Select
Case Is > 1
Temp = Temp + Huruf(Val(ax(2))) + "Puluh"
Temp = Temp + " " + Huruf(Val(ax(3)))
End Select
dgratus = Temp
End Function
Function bilangan(angka As Double) As String
Dim ratusan(0 To 6) As String
Dim sebut(0 To 4) As String
sebut(1) = " Ribu "
sebut(2) = " Juta "
sebut(3) = " Milyar "
sebut(4) = " Trilyun "
panjang = Len(Trim(Str(angka)))
kali = Int(panjang / 3)
If Int(panjang / 3) * 3 <> panjang Then
kali = kali + 1
sisa = panjang - Int(panjang / 3) * 3
nilai = Right("000", 3 - sisa) + Trim(Str(angka))
Else
nilai = Trim(Str(angka))
End If

For x = 0 To kali
ratusan(kali - x) = Mid(nilai, x * 3 + 1, 3)
Next x

For y = kali To 1 Step -1


If y = 2 And Val(ratusan(y)) = 1 Then
Temp = Temp + "Seribu "
Else
If Val(ratusan(y)) = 0 Then
Temp = Temp
Else
Temp = Temp + dgratus(Val(ratusan(y)))
Temp = Temp + sebut(y - 1)
End If
End If
Next y
bilangan = Temp & " Rupiah"
End Function