Konversi Angka Menjadi Huruf dengan VB

Ada yang bingung cara buat conversi dari angka ke huruf,…Seperti contoh nilai mata uang, misalnya Rp 1.000 => Seribu Rupiah, berikut code nya..

Public Function Konversi1(ByVal nNilai As Currency, MataUang As String) As String
Dim Grade As Variant
Dim strTerbilang As String
Dim strPart As String
Dim iGrade As Byte

Grade = Array(“MILYAR “, “JUTA “, “RIBU “, “”)
strTerbilang = “”

If Len(CStr(nNilai)) > 12 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 & ” ” & MataUang & ” ###”

End Function

Private Function Konversi2(ByVal strPart As String, ByVal iGrade As Byte) As String
Dim Angka1 As Variant, 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

 

Kode berikut di buat Oleh Firman AP

 

Salam Sidabutar..

 

2 Comments

  1. Thanks.. good idea

  2. Boleh jg idenya….dan bener2 sip. Saya punya jg source code program yg sama mngkn sebagai perbandingan bagi saya dan buat bahan belajar.


Comments RSS TrackBack Identifier URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s