TERBILANG PADA MICROSOFT VISUAL BASIC 6.0




Sekedar share tentang kode terbilang pada Visual Basic 6.0 Silahkan di Copas ya....
Buat module dan letakan kode berikut :

Public Function Terbilang(X As Double) As String
Dim tanda As Boolean
Dim teks As String
Dim tampung As Double
Dim bagian As String
Dim i As Integer

Dim letak(5)
letak(1) = "Ribu "
letak(2) = "Juta "
letak(3) = "Milyar "
letak(4) = "Trilyun "

If (X = 0) Then
Terbilang = "Nol"
Exit Function
End If

If (X < 2000) Then
tanda = True
End If
 teks = ""
 If(X >= 1E+15) Then
    Terbilang = "Nilai terlalu besar"
    Exit Function
End If

 For i = 4 To 1 Step -1
    tampung = Int(X / (10 ^ (3 * i)))
    If(tampung > 0) Then
        bagian = ratusan(tampung, tanda)
        teks = teks & bagian & letak(i)
    End If
    X = X - tampung * (10 ^ (3 * i))
Next
 teks = teks & ratusan(X, False)
Terbilang = teks & "Rupiah"
End Function

Function ratusan(ByVal Y As Double, ByVal flag As Boolean) As String
Dim tmp As Double
Dim bilang As String
Dim bag As String
Dim j As Integer

Dim angka(9)
angka(1) = "Se"
angka(2) = "Dua "
angka(3) = "Tiga "
angka(4) = "Empat "
angka(5) = "Lima "
angka(6) = "Enam "
angka(7) = "Tujuh "
angka(8) = "Delapan "
angka(9) = "Sembilan "

Dim posisi(2)
posisi(1) = "Puluh "
posisi(2) = "Ratus "

bilang = ""
For j = 2 To 1 Step -1
    tmp = Int(Y / (10 ^ j))
    If(tmp > 0) Then
        bag = angka(tmp)
        If (j = 1 And tmp = 1) Then
            Y = Y - tmp * 10 ^ j
            If (Y >= 1) Then
                posisi(j) = "Belas "
            Else
                angka(Y) = "Se"
            End If
            bilang = bilang & angka(Y) & posisi(j)
            ratusan = bilang
            Exit Function
        Else
            bilang = bilang & bag & posisi(j)
        End If
    End If

    Y = Y - tmp * 10 ^ j
Next

If (flag = False) Then
    angka(1) = "Satu "
End If
bilang = bilang & angka(Y)
ratusan = bilang
End Function