'Fungsi Terbilang dengan VBA untuk MS
Office'Ditulis oleh maseko'Fungsi penterjemahan masing-masing angkaPrivate
Function KeKata(Nomor)TrjKata = Array("", "satu",
"dua", "tiga", "empat", "lima",
"enam", "tujuh", "delapan",
"sembilan")KeKata = TrjKata(Nomor)End Function'Mulai penulisan Fungsi
TerbilangPublic Function terbilang(Nilai_Angka, Optional Style = 4, Optional Satuan = "")Angka = Fix(Abs(Nilai_Angka))'Desimal dibelakang komades1 = Mid(Abs(Nilai_Angka), Len(Angka) + 2, 1)des2 = Mid(Abs(Nilai_Angka), Len(Angka) + 3, 1)If des2 = "" Then If des1 = "" Or des1 = "0" Then Koma = "" Else Koma = " koma " & KeKata(des1) End IfElseIf des2 = "0" Then If des1 = "0" Then Koma = "" ElseIf des1 = "1" Then Koma = " koma sepuluh" Else Koma = " koma " & KeKata(des1) & " puluh" End IfElse If des1 = "0" Then Koma = " koma nol " & KeKata(des2) ElseIf des1 = "1" Then If des2 = "1" Then Koma = " koma sebelas" Else Koma = " koma " & KeKata(des2) & " belas" End If Else Koma = " koma " & KeKata(des1)
& " puluh " & KeKata(des2) End IfEnd If'Misahin AngkaNo1 = Left(Right(Angka, 1), 1)No2 = Left(Right(Angka, 2), 1)No3 = Left(Right(Angka, 3), 1)No4 = Left(Right(Angka, 4), 1)No5 = Left(Right(Angka, 5), 1)No6 = Left(Right(Angka, 6), 1)No7 = Left(Right(Angka, 7), 1)No8 = Left(Right(Angka, 8), 1)No9 = Left(Right(Angka, 9), 1)No10 = Left(Right(Angka, 10), 1)No11 = Left(Right(Angka, 11), 1)No12 = Left(Right(Angka, 12), 1)No13 = Left(Right(Angka, 13), 1)No14 = Left(Right(Angka, 14), 1)No15 = Left(Right(Angka, 15), 1)'SatuanIf Len(Angka) >= 1 Then If Len(Angka) = 1 And No1 = 1 Then Nomor1 = "satu" ElseIf Len(Angka) = 1 And No1 = 0 Then Nomor1 = "Nol" ElseIf No2 = "1" Then If No1 = "1" Then Nomor1 = "sebelas" ElseIf No1 = "0" Then Nomor1 = "sepuluh" Else Nomor1 = KeKata(No1) & " belas" End If Else Nomor1 = KeKata(No1) End IfElseNomor1 = ""End If'PuluhanIf Len(Angka) >= 2 Then If No2 = 1 Or No2 = "0" Then Nomor2 = "" Else Nomor2 = KeKata(No2) & " puluh " End IfElseNomor2 = ""End If'RatusanIf Len(Angka) >= 3 Then If No3 = "1" Then Nomor3 = "seratus " ElseIf No3 = "0" Then Nomor3 = "" Else Nomor3 = KeKata(No3) & " ratus " End IfElseNomor3 = ""End If'RibuanIf Len(Angka) >= 4 Then If No6 = "0" And No5 = "0" And No4 = "0" Then Nomor4 = "" ElseIf (No4 = "1" And Len(Angka) = 4) Or (No6 = "0" And No5 = "0" And No4 = "1") Then Nomor4 = "seribu " ElseIf No5 = "1" Then If No4 = "1" Then Nomor4 = "sebelas ribu " ElseIf No4 = "0" Then Nomor4 = "sepuluh ribu " Else Nomor4 = KeKata(No4) & " belas ribu " End If Else Nomor4 = KeKata(No4) & " ribu " End IfElseNomor4 = ""End If'Puluhan ribuIf Len(Angka) >= 5 Then If No5 = "1" Or No5 = "0" Then Nomor5 = "" Else Nomor5 = KeKata(No5) & " puluh " End IfElseNomor5 = ""End If'Ratusan RibuIf Len(Angka) >= 6 Then If No6 = "1" Then Nomor6 = "seratus " ElseIf No6 = "0" Then Nomor6 = "" Else Nomor6 = KeKata(No6) & " ratus " End IfElseNomor6 = ""End If'JutaanIf Len(Angka) >= 7 Then If No9 = "0" And No8 = "0" And No7 = "0" Then Nomor7 = "" ElseIf No7 = "1" And Len(Angka) = 7 Then Nomor7 = "satu juta " ElseIf No8 = "1" Then If No7 = "1" Then Nomor7 = "sebelas juta " ElseIf No7 = "0" Then Nomor7 = "sepuluh juta " Else Nomor7 = KeKata(No7) & " belas juta " End If Else Nomor7 = KeKata(No7) & " juta " End IfElseNomor7 = ""End If'Puluhan jutaIf Len(Angka) >= 8 Then If No8 = "1" Or No8 = "0" Then Nomor8 = "" Else Nomor8 = KeKata(No8) & " puluh " End IfElseNomor8 = ""End If'Ratusan jutaIf Len(Angka) >= 9 Then If No9 = "1" Then Nomor9 = "seratus " ElseIf No9 = "0" Then Nomor9 = "" Else Nomor9 = KeKata(No9) & " ratus " End IfElseNomor9 = ""End If'MilyarIf Len(Angka) >= 10 Then If No12 = "0" And No11 = "0" And No10 = "0" Then Nomor10 = "" ElseIf No10 = "1" And Len(Angka) = 10 Then Nomor10 = "satu milyar " ElseIf No11 = "1" Then If No10 = "1" Then Nomor10 = "sebelas milyar " ElseIf No10 = "0" Then Nomor10 = "sepuluh milyar " Else Nomor10 = KeKata(No10) & " belas milyar " End If Else Nomor10 = KeKata(No10) & " milyar " End IfElseNomor10 = ""End If'Puluhan MilyarIf Len(Angka) >= 11 Then If No11 = "1" Or No11 = "0" Then Nomor11 = "" Else Nomor11 = KeKata(No11) & " puluh " End IfElseNomor11 = ""End If'Ratusan MilyarIf Len(Angka) >= 12 Then If No12 = "1" Then Nomor12 = "seratus " ElseIf No12 = "0" Then Nomor12 = "" Else Nomor12 = KeKata(No12) & " ratus " End IfElseNomor12 = ""End If'TriliunIf Len(Angka) >= 13 Then If No15 = "0" And No14 = "0" And No13 = "0" Then Nomor13 = "" ElseIf No13 = "1" And Len(Angka) = 13 Then Nomor13 = "satu triliun " ElseIf No14 = "1" Then If No13 = "1" Then Nomor13 = "sebelas triliun " ElseIf No13 = "0" Then Nomor13 = "sepuluh triliun " Else Nomor13 = KeKata(No13) & " belas triliun " End If Else Nomor13 = KeKata(No13) & " triliun " End IfElseNomor13 = ""End If'Puluhan triliunIf Len(Angka) >= 14 Then If No14 = "1" Or No14 = "0" Then Nomor14 = "" Else Nomor14 = KeKata(No14) & " puluh " End IfElseNomor14 = ""End If'Ratusan triliunIf Len(Angka) >= 15 Then If No15 = "1" Then Nomor15 = "seratus " ElseIf No15 = "0" Then Nomor15 = "" Else Nomor15 = KeKata(No15) & " ratus " End IfElseNomor15 = ""End IfIf Len(Angka) > 15 Thenbilang = "Digit Angka Terlalu Banyak"Else If IsNull(Nilai_Angka) Then bilang = "" ElseIf Nilai_Angka < 0 Then bilang = "minus " & Trim(Nomor15 & Nomor14 & Nomor13 & Nomor12 & Nomor11 & Nomor10 & Nomor9 & Nomor8 & Nomor7 _ & Nomor6 & Nomor5 & Nomor4 & Nomor3 & Nomor2 & Nomor1 & Koma & " " & Satuan) Else bilang = Trim(Nomor15 & Nomor14 & Nomor13 & Nomor12 & Nomor11 & Nomor10 & Nomor9 & Nomor8 & Nomor7 _ & Nomor6 & Nomor5 & Nomor4 & Nomor3 & Nomor2 & Nomor1 & Koma & " " & Satuan) End IfEnd IfIf Style = 4 Thenterbilang = StrConv(Left(bilang, 1), 1) & StrConv(Mid(bilang, 2, 1000), 2)Elseterbilang = StrConv(bilang, Style)End Ifterbilang = Replace(terbilang, " ", " ", 1, 1000, vbTextCompare)End Function
TerbilangPublic Function terbilang(Nilai_Angka, Optional Style = 4, Optional Satuan = "")Angka = Fix(Abs(Nilai_Angka))'Desimal dibelakang komades1 = Mid(Abs(Nilai_Angka), Len(Angka) + 2, 1)des2 = Mid(Abs(Nilai_Angka), Len(Angka) + 3, 1)If des2 = "" Then If des1 = "" Or des1 = "0" Then Koma = "" Else Koma = " koma " & KeKata(des1) End IfElseIf des2 = "0" Then If des1 = "0" Then Koma = "" ElseIf des1 = "1" Then Koma = " koma sepuluh" Else Koma = " koma " & KeKata(des1) & " puluh" End IfElse If des1 = "0" Then Koma = " koma nol " & KeKata(des2) ElseIf des1 = "1" Then If des2 = "1" Then Koma = " koma sebelas" Else Koma = " koma " & KeKata(des2) & " belas" End If Else Koma = " koma " & KeKata(des1)
& " puluh " & KeKata(des2) End IfEnd If'Misahin AngkaNo1 = Left(Right(Angka, 1), 1)No2 = Left(Right(Angka, 2), 1)No3 = Left(Right(Angka, 3), 1)No4 = Left(Right(Angka, 4), 1)No5 = Left(Right(Angka, 5), 1)No6 = Left(Right(Angka, 6), 1)No7 = Left(Right(Angka, 7), 1)No8 = Left(Right(Angka, 8), 1)No9 = Left(Right(Angka, 9), 1)No10 = Left(Right(Angka, 10), 1)No11 = Left(Right(Angka, 11), 1)No12 = Left(Right(Angka, 12), 1)No13 = Left(Right(Angka, 13), 1)No14 = Left(Right(Angka, 14), 1)No15 = Left(Right(Angka, 15), 1)'SatuanIf Len(Angka) >= 1 Then If Len(Angka) = 1 And No1 = 1 Then Nomor1 = "satu" ElseIf Len(Angka) = 1 And No1 = 0 Then Nomor1 = "Nol" ElseIf No2 = "1" Then If No1 = "1" Then Nomor1 = "sebelas" ElseIf No1 = "0" Then Nomor1 = "sepuluh" Else Nomor1 = KeKata(No1) & " belas" End If Else Nomor1 = KeKata(No1) End IfElseNomor1 = ""End If'PuluhanIf Len(Angka) >= 2 Then If No2 = 1 Or No2 = "0" Then Nomor2 = "" Else Nomor2 = KeKata(No2) & " puluh " End IfElseNomor2 = ""End If'RatusanIf Len(Angka) >= 3 Then If No3 = "1" Then Nomor3 = "seratus " ElseIf No3 = "0" Then Nomor3 = "" Else Nomor3 = KeKata(No3) & " ratus " End IfElseNomor3 = ""End If'RibuanIf Len(Angka) >= 4 Then If No6 = "0" And No5 = "0" And No4 = "0" Then Nomor4 = "" ElseIf (No4 = "1" And Len(Angka) = 4) Or (No6 = "0" And No5 = "0" And No4 = "1") Then Nomor4 = "seribu " ElseIf No5 = "1" Then If No4 = "1" Then Nomor4 = "sebelas ribu " ElseIf No4 = "0" Then Nomor4 = "sepuluh ribu " Else Nomor4 = KeKata(No4) & " belas ribu " End If Else Nomor4 = KeKata(No4) & " ribu " End IfElseNomor4 = ""End If'Puluhan ribuIf Len(Angka) >= 5 Then If No5 = "1" Or No5 = "0" Then Nomor5 = "" Else Nomor5 = KeKata(No5) & " puluh " End IfElseNomor5 = ""End If'Ratusan RibuIf Len(Angka) >= 6 Then If No6 = "1" Then Nomor6 = "seratus " ElseIf No6 = "0" Then Nomor6 = "" Else Nomor6 = KeKata(No6) & " ratus " End IfElseNomor6 = ""End If'JutaanIf Len(Angka) >= 7 Then If No9 = "0" And No8 = "0" And No7 = "0" Then Nomor7 = "" ElseIf No7 = "1" And Len(Angka) = 7 Then Nomor7 = "satu juta " ElseIf No8 = "1" Then If No7 = "1" Then Nomor7 = "sebelas juta " ElseIf No7 = "0" Then Nomor7 = "sepuluh juta " Else Nomor7 = KeKata(No7) & " belas juta " End If Else Nomor7 = KeKata(No7) & " juta " End IfElseNomor7 = ""End If'Puluhan jutaIf Len(Angka) >= 8 Then If No8 = "1" Or No8 = "0" Then Nomor8 = "" Else Nomor8 = KeKata(No8) & " puluh " End IfElseNomor8 = ""End If'Ratusan jutaIf Len(Angka) >= 9 Then If No9 = "1" Then Nomor9 = "seratus " ElseIf No9 = "0" Then Nomor9 = "" Else Nomor9 = KeKata(No9) & " ratus " End IfElseNomor9 = ""End If'MilyarIf Len(Angka) >= 10 Then If No12 = "0" And No11 = "0" And No10 = "0" Then Nomor10 = "" ElseIf No10 = "1" And Len(Angka) = 10 Then Nomor10 = "satu milyar " ElseIf No11 = "1" Then If No10 = "1" Then Nomor10 = "sebelas milyar " ElseIf No10 = "0" Then Nomor10 = "sepuluh milyar " Else Nomor10 = KeKata(No10) & " belas milyar " End If Else Nomor10 = KeKata(No10) & " milyar " End IfElseNomor10 = ""End If'Puluhan MilyarIf Len(Angka) >= 11 Then If No11 = "1" Or No11 = "0" Then Nomor11 = "" Else Nomor11 = KeKata(No11) & " puluh " End IfElseNomor11 = ""End If'Ratusan MilyarIf Len(Angka) >= 12 Then If No12 = "1" Then Nomor12 = "seratus " ElseIf No12 = "0" Then Nomor12 = "" Else Nomor12 = KeKata(No12) & " ratus " End IfElseNomor12 = ""End If'TriliunIf Len(Angka) >= 13 Then If No15 = "0" And No14 = "0" And No13 = "0" Then Nomor13 = "" ElseIf No13 = "1" And Len(Angka) = 13 Then Nomor13 = "satu triliun " ElseIf No14 = "1" Then If No13 = "1" Then Nomor13 = "sebelas triliun " ElseIf No13 = "0" Then Nomor13 = "sepuluh triliun " Else Nomor13 = KeKata(No13) & " belas triliun " End If Else Nomor13 = KeKata(No13) & " triliun " End IfElseNomor13 = ""End If'Puluhan triliunIf Len(Angka) >= 14 Then If No14 = "1" Or No14 = "0" Then Nomor14 = "" Else Nomor14 = KeKata(No14) & " puluh " End IfElseNomor14 = ""End If'Ratusan triliunIf Len(Angka) >= 15 Then If No15 = "1" Then Nomor15 = "seratus " ElseIf No15 = "0" Then Nomor15 = "" Else Nomor15 = KeKata(No15) & " ratus " End IfElseNomor15 = ""End IfIf Len(Angka) > 15 Thenbilang = "Digit Angka Terlalu Banyak"Else If IsNull(Nilai_Angka) Then bilang = "" ElseIf Nilai_Angka < 0 Then bilang = "minus " & Trim(Nomor15 & Nomor14 & Nomor13 & Nomor12 & Nomor11 & Nomor10 & Nomor9 & Nomor8 & Nomor7 _ & Nomor6 & Nomor5 & Nomor4 & Nomor3 & Nomor2 & Nomor1 & Koma & " " & Satuan) Else bilang = Trim(Nomor15 & Nomor14 & Nomor13 & Nomor12 & Nomor11 & Nomor10 & Nomor9 & Nomor8 & Nomor7 _ & Nomor6 & Nomor5 & Nomor4 & Nomor3 & Nomor2 & Nomor1 & Koma & " " & Satuan) End IfEnd IfIf Style = 4 Thenterbilang = StrConv(Left(bilang, 1), 1) & StrConv(Mid(bilang, 2, 1000), 2)Elseterbilang = StrConv(bilang, Style)End Ifterbilang = Replace(terbilang, " ", " ", 1, 1000, vbTextCompare)End Function
0 comments:
Post a Comment