Seperti yang pernah rekan pembaca lakukan pada pembelian atau pembayaran atau menabung di bank, ada 'angka' yang menunjukkan banyaknya uang yang mau disetor tersebut, ada pula 'kalimat' yang menunjukkan banyaknya uang yang mau disetor tersebut, yang biasanya bertuliskan 'terbilang'.
Contoh:
100.000
Terbilang: Seratus ribu.
Untuk mahasiswa yang sedang ada tugas Visual Basic 6.0 yang berkaitan dengan kasus tersebut, silakan pelajari Script atau Source Code Visual Basic ini:
'Belajar Visual Basic 6.0
'Tambahkan: 1 TextBox, 1 CommandButton, 1 Label
'Riyan Hidayat Samosir in BeKaBe.BlogSpot.Com
Function SayNumber(nNumber As Variant, _
Optional SayKoma As Boolean = False) As String
Dim i As Long
Dim s As String
Dim s2 As Double
Dim x As String
Dim minus As Boolean
Dim nBulat As Double
If TypeName(nNumber) = "String" Then
If Trim(Mid$(nNumber, 1, 1) = "-") Then
minus = True
nNumber = Mid(nNumber, 2)
End If
x = Trim(CDbl(nNumber))
Else
If nNumber < 0 Then
nNumber = Abs(nNumber)
minus = True
End If
x = FormatNumber(nNumber, 2)
End If
s = SayN(Int(nNumber))
If minus Then SayNumber = "Minus " & s Else SayNumber = s
End Function
Function SayN(nNumber As Double) As String
Dim z, s, a, c, x
Dim ulang As Double
Dim i As Byte
Dim tampung(5) As String
Dim n As String
n = LTrim(RTrim(nNumber))
ulang = (Len(n) - 1) \ 3 + 1
For i = 1 To ulang
If Len(n) > 3 Then
c = Mid$(n, Len(n) - 2, 3)
n = Mid$(n, 1, Len(n) - 3)
tampung(i) = c
Else
tampung(i) = n
End If
Next i
z = ""
If n = "0" Then
z = "Nol "
Else
i = ulang
Do
a = ""
x = ""
s = tampung(i)
While Len(s) < 3
s = "0" + s
Wend
'digit ratusan
If Mid$(s, 1, 1) <> "0" Then
If Mid$(s, 1, 1) = "1" Then
a = a + "Seratus "
Else
a = a + Nama(Mid$(s, 1, 1)) + "Ratus "
End If
End If
'digit 11-19
If Mid$(s, 2, 1) = "1" Then
If (Mid$(s, 3, 1) <> "1") And (Mid$(s, 3, 1) <> "0") Then
a = a + Nama(Mid$(s, 3, 1)) + "Belas "
End If
If Mid$(s, 3, 1) = "1" Then a = a + "Sebelas "
If Mid$(s, 3, 1) = "0" Then a = a + "Sepuluh "
End If
'digit puluhan
If (Mid$(s, 2, 1) <> "1") And _
(s <> "000") And (Mid$(s, 2, 1) <> "0") Then
a = a + Nama(Mid$(s, 2, 1)) + "Puluh "
End If
If (Mid$(s, 3, 1) <> "0") And (Mid$(s, 2, 1) <> "1") Then
a = a + Nama(Mid$(s, 3, 1))
End If
'perkecualian untuk seribu
If (i = 2) Then
If s = "001" Then a = "Se"
End If
If s <> "000" Then
If i = 1 Then x = ""
If i = 2 Then x = "Ribu "
If i = 3 Then x = "Juta "
If i = 4 Then x = "Miliar "
If i = 5 Then x = "Triliun "
End If
If a = "Se" Then x = LCase(x)
z = z + a + x
i = i - 1
Loop Until i = 0
End If
SayN = z
End Function
Private Function Nama(a As String) As String
Select Case a
Case "1": Nama = "Satu "
Case "2": Nama = "Dua "
Case "3": Nama = "Tiga "
Case "4": Nama = "Empat "
Case "5": Nama = "Lima "
Case "6": Nama = "Enam "
Case "7": Nama = "Tujuh "
Case "8": Nama = "Delapan "
Case "9": Nama = "Sembilan "
Case "0": Nama = ""
End Select
End Function
Private Sub Command1_Click()
Label1.Caption = SayNumber(Text1.Text)
End Sub
sumber: http://bekabe.blogspot.com/2011/04/visual-basic-membuat-fungsi-terbilang.html
Tidak ada komentar:
Posting Komentar