membuat terbilang pada vb
Public Function konversi1(ByVal nNilai As Currency) As String Dim Grade As Variant Dim strTerbilang As String Dim strPart As String Dim iGrade As Byte Grade = Array("Milyar ", "Juta ", "Ribu ", "") strTerbilang = "" 'Kalo lebih dari 12 digit If Len(CStr(nNilai)) > 14 Then strTerbilang = "Melebihi batas maksimum !" Else strPart = Format(nNilai, String(12, "0")) For iGrade = 1 To 4 If Val(Mid(strPart, (iGrade - 1) * 3 + 1, 3)) > 0 Then strTerbilang = strTerbilang & konversi2(Mid(strPart, (iGrade - 1) * 3 + 1, 3), iGrade) strTerbilang = strTerbilang & Grade(iGrade - 1) End If Next iGrade End If konversi1 = strTerbilang End Function Public Function konversi2(ByVal strPart As String, _ ByVal iGrade As Byte) As String Dim Angka1 As Variant Dim Angka2 As Variant Dim i As Integer Dim strHasil As String Dim nTemp As Byte Angka1 = Array("Satu ", "Dua ", "Tiga ", "Empat ", "Lima ", _ "Enam ", "Tujuh ", "Delapan ", "Sembilan ") Angka2 = Array("Ratus ", "Puluh ", "") For i = 1 To 3 nTemp = Val(Mid(strPart, i, 1)) If nTemp = 1 Then If i = 1 Then strHasil = "Seratus " ElseIf i = 2 Then i = i + 1 nTemp = Val(Mid(strPart, i, 1)) If nTemp = 0 Then strHasil = strHasil & "Sepuluh " ElseIf nTemp = 1 Then strHasil = strHasil & "Sebelas " Else strHasil = strHasil & Angka1(nTemp - 1) & "Belas " End If ElseIf Val(strPart) = 1 And iGrade = 3 Then strHasil = strHasil & "Se" Else strHasil = strHasil & "Satu " End If ElseIf nTemp <> 0 Then strHasil = strHasil + Angka1(nTemp - 1) + Angka2(i - 1) End If Next i konversi2 = strHasil End Function 'cara menggunakan : 'ambil 2 textbox 'masukan perintah :
Private Sub Text1_Change() Text2.Text = konversi1(Text1) End Sub
semoga bermanfaat, buat para master kalo dalam scrip ini ada yang salah newbe mohon maaf
0 comments:
Post a Comment