Konversi number ke text(terbilang) di vb6.0

Ok, langsung aja pake juruz copy paste ya:

===========================Start=========================

‘/*instance convert number to teks*/
‘/*Author by Yanto Hariyono*/

Private Function TAngka(Angka) As String
Select Case Angka
Case 0: TAngka = “Nol ”
Case 1: TAngka = “Satu ”
Case 2: TAngka = “Dua ”
Case 3: TAngka = “Tiga ”
Case 4: TAngka = “Empat ”
Case 5: TAngka = “Lima ”
Case 6: TAngka = “Enam ”
Case 7: TAngka = “Tujuh ”
Case 8: TAngka = “Delapan ”
Case 9: TAngka = “Sembilan ”
End Select
End Function

Private Function Angka3D(Angka) As String
‘memecah angka menjadi ratusan, puluhan dan satuan
sat = Mid(Angka, Len(Angka), 1)
If Len(Angka) >= 2 Then
pul = Mid(Angka, Len(Angka) – 1, 1)
If Len(Angka) = 3 Then
rat = Mid(Angka, Len(Angka) – 2, 1)
If Len(Angka) = 4 Then
rib = Mid(Angka, Len(Angka) – 3, 1)
End If
End If
End If

‘untuk Ratusan
Select Case rib
Case 0: tb = “”
Case 1: tb = “Seribu ”
Case Else: tb = TAngka(rat) & “Ribu ”
End Select
‘untuk Ratusan
Select Case rat
Case 0: tr = “”
Case 1: tr = “Seratus ”
Case Else: tr = TAngka(rat) & “Ratus ”
End Select
‘untuk Puluhan
Select Case pul
Case 0: tp = “”
Case 1: Select Case sat
Case 0: tp = “Sepuluh ”
Case 1: tp = “Sebelas ”
Case Else: tp = TAngka(sat) & “Belas ”
End Select
GoTo final
Case Else: tp = TAngka(pul) & “Puluh ”
End Select
‘untuk Satuan
Select Case sat
Case 0: ts = “”
Case Else: ts = TAngka(sat)
End Select

final:
Angka3D = tr & tp & ts
End Function

Private Function BcAng(Angka) As String
Dim Group(9)

Teks = “”
pj = Len(Angka)
If pj > 27 Then
MsgBox “Digit terlalu panjang ! ” & vbCrLf & “Maksimum 27 Digit”
Else
‘menghitung jumlah group
n = pj \ 3
‘untuk group sisa
If (pj Mod 3) <> 0 Then
Group(n + 1) = Mid(Angka, 1, pj – 3 * n)
If (Group(n + 1) = 1 And ((n + 1) = 2) Or (n + 1) = 6) Then
Teks = “Se”
Else
Teks = Angka3D(Group(n + 1))
End If
If Teks <> “” Then
Select Case n + 1
Case 2: Teks = Teks & “Ribu ”
Case 3: Teks = Teks & “Juta ”
Case 4: Teks = Teks & “Milyar ”
Case 5: Teks = Teks & “Trilyun ”
Case 6: Teks = Teks & “Ribu Trilyun ”
Case 7: Teks = Teks & “Juta Trilyun ”
Case 8: Teks = Teks & “Milyar Trilyun ”
Case 9: Teks = Teks & “Trilyun Trilyun ”
End Select
End If
End If

‘untuk masing-masing group
For i = n To 1 Step -1
Group(i) = Mid(Angka, pj – 3 * i + 1, 3)
If Group(i) = 1 And (i = 2 Or i = 6) Then
Teks = Teks & “Se”
Else
Teks = Teks & Angka3D(Group(i))
End If

If Angka3D(Group(i)) <> “” Then
Select Case i
Case 2: Teks = Teks & “ribu ”
Case 3: Teks = Teks & “juta ”
Case 4: Teks = Teks & “milyar ”
Case 5: Teks = Teks & “trilyun ”
Case 6: Teks = Teks & “ribu Trilyun ”
Case 7: Teks = Teks & “juta Trilyun ”
Case 8: Teks = Teks & “milyar Trilyun ”
Case 9: Teks = Teks & “trilyun Trilyun ”
End Select
End If
Next i
If Angka = 0 Then Teks = “Nol ”
BcAng = Teks
End If
End Function

Private Function AdaKoma(Teks) As Boolean
AdaKoma = False
For i = 1 To Len(Teks)
st = Mid(Teks, i, 1)
If st = “.” Or st = “,” Then
AdaKoma = True
End If
Next i
End Function

Private Function AdaRupiah(Teks) As Boolean
AdaRupiah = False
If UCase(Left(Teks, 2)) = “RP” Then AdaRupiah = True
End Function

Private Function AdaNegatif(Teks) As Boolean
AdaNegatif = False
If Left(Teks, 1) = ” – ” Then AdaNegatif = True
End Function

Public Function bacaangka(Angka, Optional Satuan = “”) As String
Dim scr() As String
Dim i As Integer
If AdaRupiah(Angka) Then
smt = bacaangka(Right(Angka, Len(Angka) – 2))
bacaangka = smt & ” rupiah”
Exit Function
End If

If AdaNegatif(Angka) Then
smt = bacaangka(Right(Angka, Len(Angka) – 1))
bacaangka = “negatif ” & smt
Exit Function
End If

If AdaKoma(Angka) Then
kt = InStr(1, Angka, “, “)

If kt = 0 Then
sp = Split(Angka, “,”)
Else
sp = Split(Angka, “0”)
End If

bacaangka = BcAng(sp(0)) & “Koma ”
For i = 1 To Len(sp(1))
bacaangka = bacaangka & TAngka(Mid(sp(1), i, 1))
Next i

scr = Split(bacaangka & TAngka(Mid(sp(1), i, 1)) & Satuan, ” “, -1, 1)
Else
scr = Split(BcAng(Angka) & Satuan, ” “, -1, 1)
End If

bacaangka = “”

i = 0
While i < i + 1
On Error GoTo hndl
bacaangka = bacaangka & ” ” & Trim(UCase$(Mid(Trim(scr(i)), 1, 1)) & LCase$(Mid(Trim(scr(i)), 2, 100)))
i = i + 1
Wend

hndl:
bacaangka = bacaangka
End Function

==========================End========================

Atau download aja disini.

^_^ by MRTHX

  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: