Kali ini kita akan membuat funtion terbilang dalam bahasa inggris.
Asyik ga' tu?
Ni kodingnya :
Function SAYWORD(Angka As Double) As String
'SAYWORD = Ubah Angka menjadi Huruf dalam Bahasa Inggris
Dim StrAngka As String
Dim AngkaI(15) As Integer
Dim Nomor(9) As String
Dim Nomor1(9) As String
Dim Temp As String
Dim Hurufke(15) As String
Nomor(1) = "one "
Nomor(2) = "two "
Nomor(3) = "three "
Nomor(4) = "four "
Nomor(5) = "five "
Nomor(6) = "six "
Nomor(7) = "seven "
Nomor(8) = "eight "
Nomor(9) = "nine "
Nomor1(1) = ""
Nomor1(2) = "twen"
Nomor1(3) = "thir"
Nomor1(4) = "for"
Nomor1(5) = "fif"
Nomor1(6) = "six"
Nomor1(7) = "seven"
Nomor1(8) = "eigh"
Nomor1(9) = "nine"
StrAngka = Str(Angka)
Panjang = Len(Str(Angka)) - 1
'SAYWORD
'Tambahkan Angka 0000 didepan Angka Asli menjadi String
'dengan Variabel StrAngka
'contoh StrAngka = "000012345"
StrAngka = ""
For i = 1 To 15 - Panjang
StrAngka = "0" + StrAngka
Next i
StrAngka = StrAngka + Right(Str(Angka), Panjang)
'Ambil masing-masing Angka dari Belakang ke depan
'Digit 1 = Ones
'Digit 2 = Tens
'Digit 3 = Hundreds
'Digit 4 = Thousands
'Digit 5 = Ten Thousands
' dst......
For i = 1 To 15
AngkaI(i) = Val(Mid(StrAngka, 16 - i, 1))
Next i
'Ubah menjadi Huruf
'Satuan = digit Terakhir
If AngkaI(2) = 0 Then
Hurufke(1) = Nomor(AngkaI(1))
End If
If Angka = 0 Then
Hurufke(1) = "null"
End If
'Puluhan = digit ke 2 dari belakang
'Untuk digit ke 5, 8, 11 dst.... merupakan tens thousand, tens
'million dst..
For i = 2 To 15 Step 3
Select Case AngkaI(i)
Case 0 'Bila Angka Puluhan = 0 -> Temp = ""
Temp = ""
Case 1 'Bila Angka Puluhan = 1
'Check Angka dibelakangnya
Select Case AngkaI(i - 1)
Case 0 'Bila = 0 -> Temp = "ten"
Temp = "ten "
Case 1 'Bila = 1 -> Temp = "eleven"
Temp = "eleven "
Case 2
Temp = "twelve "
Case Else 'Bila Angka dibelakangnya > 2 -> Temp = "xxxteen"
Temp = Nomor1(AngkaI(i - 1)) + "teen "
End Select
Case Else
'Bila Angka puluhan > 1
'maka Temp = "xxx ty yyy"
Temp = Nomor1(AngkaI(i)) + "ty " + Nomor(AngkaI(i - 1))
End Select
Hurufke(i) = Temp
Next i
'Ratusan
'Digit Ke 3, 6, 9, ... dst merupakan hundred, hundred thousand, hundred million, dst..
For i = 3 To 15 Step 3
Select Case AngkaI(i)
Case 0
Temp = ""
Case Else
Temp = Nomor(AngkaI(i)) + "hundred "
End Select
Hurufke(i) = Temp
Next i
'Ribuan, Jutaan, Miliar, Triliun
'Digit ke 4 = Ribuan
'Digit ke 7 = Jutaan
'Digit ke 10 = Miliar
'Digit ke 13 = Triliun
For i = 4 To 15 Step 3
If AngkaI(i + 1) = 0 Then
Temp = Nomor(AngkaI(i))
Else
Temp = ""
End If
Select Case i
Case 4
Temp = Temp + "thousand "
Case 7
Temp = Temp + "million "
Case 10
Temp = Temp + "billion "
Case 13
Temp = Temp + "trillion "
End Select
'Check apakah Pada digit ke(i), ke (i+1) , ke (i+2)
'bila semuanya = 0 -> Hurufke(i) = ""
'Bila tidak -> Hurufke(i) = temp
If AngkaI(i) = 0 And AngkaI(i + 1) = 0 And AngkaI(i + 2) = 0 Then
Hurufke(i) = ""
Else
Hurufke(i) = Temp
End If
Next i
SAYWORD = ""
For i = 1 To 15
SAYWORD = SAYWORD + Hurufke(16 - i)
Next i
End Function
Silakan di coba ya.....!Oh iya makasih komentarnya...
Klu ga' ada Visual Basic Editor?
Berarti anda belum menginstal visual basic!
Instal dulu ya....