Posted by: Red Souldier | May 26, 2009

Function Terbilang (Number to text) in Indonesian Language using crystal report

After googling the net to find anyone who post on how to create function Terbilang in crystal report, finally I found one site thats really works.

The original source is from here:

http://oyongweb.com/blog/?p=67

So first step is you need to create 4 function, first function is:

Function Bilangan (x as Number)
Select Case  x
Case 0
Bilangan = ""
case 1
Bilangan = "satu "
case 2
Bilangan = "dua "
case 3
Bilangan = "tiga "
case 4
Bilangan = "empat "
case 5
Bilangan = "lima "
case 6
Bilangan = "enam "
case 7
Bilangan = "tujuh "
case 8
Bilangan = "delapan "
case 9
Bilangan = "sembilan "
case 10
Bilangan = "sepuluh "
case 11
Bilangan = "sebelas "

End Select

End Function

Second Function

Function DictDown (x as Number) as String
Select Case  x
Case 0
DictDown = "ratus "
case 1
DictDown = ""
case 2
DictDown = "puluh "
End Select

End Function

Third Function

Function DictUp (x as Number) as string
Select Case  x
Case 0
DictUp = ""
case 1
DictUp = "ribu "
case 2
DictUp = "juta "
case 3
DictUp = "milyar "
case 4
DictUp = "triliun"
End Select

End Function

Last Function that we will be using to call the converter is:

Function getTerbilang (x as Number) as String
Dim out as String
dim inp as String
dim temp as string
dim temp2 as string
dim add as string
Dim pjg, j As Number
Dim flagEmpty As Boolean
flagEmpty = True
out = ""
inp = cstr (x,0,"","")
pjg = Len(inp)
temp = ""
temp2 = ""

For j = 0 To pjg - 1  Step 1
temp = Mid(inp,j+1, 1)

If (pjg - j) Mod 3 = 0 Then
flagEmpty = True
End If

If temp = "0" Then
add = ""
ElseIf temp = "1" And ((pjg - j) Mod 3 <> 1 Or (j = 0 And pjg <> 1)) Then
add = ""
If (pjg - j) Mod 3 = 2 Then
temp2 = Mid(inp,j + 2, 1) 'if 12, then read the 2
If temp2 = "1" Or temp2 = "0" Then
add = add & "Se"
Else
add = add & bilangan(cdbl(temp2))
End If
If temp2 = "0" Then
add = add & "puluh "
Else
add = add & "belas "
End If

j = j + 1 'This part read two number simultaneusly Example 112 it read 12 both.
Else
add = "Se"
add = add & dictDown((pjg - j) Mod 3)
End If

flagEmpty = False
Else
add = bilangan(CDbl(temp)) & dictDown((pjg - j) Mod 3)
flagEmpty = False
End If

If (pjg - j) Mod 3 = 1 And flagEmpty = False Then
add = add & dictUp((pjg - j - 1) \ 3)
End If

out = out & add

Next
temp = UCase(Left(out, 1))
temp2 = Mid(out,2)
out = temp & temp2
getTerbilang = out

End Function

How to use it:

Very simple, in formula editor just call the function like this getTerbilang(25000), and it will return Dua puluh lime ribu

Advertisements

Responses

  1. Penggunaan bagaimana ya… saya coba, eror message nya “A (is expected her”, trims.

    • Hi, sorry, di function terbilang ternyata ada beberapa kesalahan coding. beberapa code seperti >.< yg seharusnya . Tp sekarang udah di ganti kok.
      Cara penggunannya buat 5 costum function, kalau ga ngerti caranya coba cek ini http://www.ehow.com/how_5269529_create-custom-function-crystal-reports.html.

      Semoga membantu. Kalau butuh source code bisa reply ke saya lg ok
      Thanks

      • Telah saya coba kembali, namun eror nya masih seperti yang lalu.. saya menggunakan Crystal Report 10, source code diatas saya copy – paste, ternyata masih eror…

        Trims.


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

Categories

%d bloggers like this: