Tecnologia, programação e muito Visual FoxPro.

sexta-feira, 29 de agosto de 2014

Bls: ]] XL-mania [[ Menulis bilangan utk uang (Rupiah) [1 Attachment]

 

Bapak Edhie Wibowo

Terlampir saya sampaikan file contoh dan VBA scripnya 
Semoga bermanfaat

Effendy Karim


Pada Senin, 25 Agustus 2014 21:02, "Edhie Wibowo edhiewibowo@gmail.com [XL-mania]" <XL-mania@yahoogroups.com> menulis:


 
Dear temans,
saya mau tanya nih, ttg macro penulisan bilangan utk uang (rupiah),
dapet dari google dalam dollar, kemudian saya modifikasi jadi rupiah.
Sejauh ini sih macronya berhasil dgn baik, hanya ketika ada angka 100,
tidak bisa membacanya "seratus" tapi satu ratus, juga 10, tidak dibaca
"sepuluh", tapi satu puluh. Gimana spy bisa terbaca cara Indonesia?

Mohon solusinya dari para master. Terima kasih banyak.

-------------------------------------------
Option Explicit
'Main Function
Function SpellNumber(ByVal MyNumber)
Dim Dollars, Cents, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " ribu "
Place(3) = " juta "
Place(4) = " milyar "
Place(5) = " trilyun "
' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
DecimalPlace = InStr(MyNumber, ".")
' Convert cents and set MyNumber to dollar amount.
If DecimalPlace > 0 Then
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Dollars
Case ""
Dollars = "Tidak ada uang"
Case "One"
Dollars = "satu rupiah"
Case Else
Dollars = Dollars & " rupiah"
End Select
Select Case Cents
Case ""
Cents = " "
Case "One"
Cents = " dan satu sen"
Case Else
Cents = " and " & Cents & " sen"
End Select
SpellNumber = Dollars & Cents
End Function

' Converts a number from 100-999 into text
Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) <> "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) & " ratus "
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2))
Else
Result = Result & GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function

' Converts a number from 10 to 99 into text.
Function GetTens(TensText)
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
Select Case Val(TensText)
Case 10: Result = "sepuluh"
Case 11: Result = "sebelas"
Case 12: Result = "dua belas"
Case 13: Result = "tiga belas"
Case 14: Result = "empat belas"
Case 15: Result = "lima belas"
Case 16: Result = "enam belas"
Case 17: Result = "tujuh belas"
Case 18: Result = "Delapan Belas"
Case 19: Result = "Sembilan Belas"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "dua puluh "
Case 3: Result = "tiga puluh "
Case 4: Result = "empat puluh "
Case 5: Result = "lima puluh "
Case 6: Result = "enam puluh "
Case 7: Result = "tujuh puluh "
Case 8: Result = "delapan puluh "
Case 9: Result = "sembilan puluh "
Case Else
End Select
Result = Result & GetDigit _
(Right(TensText, 1)) ' Retrieve ones place.
End If
GetTens = Result
End Function

' Converts a number from 1 to 9 into text.
Function GetDigit(Digit)
Select Case Val(Digit)
Case 1: GetDigit = "satu"
Case 2: GetDigit = "dua"
Case 3: GetDigit = "tiga"
Case 4: GetDigit = "empat"
Case 5: GetDigit = "lima"
Case 6: GetDigit = "enam"
Case 7: GetDigit = "tujuh"
Case 8: GetDigit = "delapan"
Case 9: GetDigit = "sembilan"
Case Else: GetDigit = ""
End Select
End Function

----------------------------------------------------------

--
Jabat hangat,
Edhie Wibowo

"Vision Shows the Way, Passion Sustains the Journey"


__._,_.___
View attachments on the web

Posted by: Endut Karim <endutkarim@yahoo.co.id>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)
:: XL-mania ::::::::::::::::::::
Momods sekarang jualan tas di www.flirtypoodle.com ha ha ha....
:: ------------- ::::::::::::::::::::
DILARANG : MLM, money game, OOT, iklan tanpa izin, SARA, testing, pembicaraan pribadi, one line message,  melecehkan,  tidak sopan.
:: ------------- ::::::::::::::::::::
Buat subjek yang kreatif, jangan : &quot;tanya&quot;, &quot;help&quot;, &quot;mohon bantu&quot;
Usahakan besar attachment &lt; 200 kb. Gunakan  winzip  jika  perlu.
:: ------------- ::::::::::::::::::::
Ajak teman-teman Anda bergabung dengan mengirim e-mail kosong ke
XL-mania-subscribe@yahoogroups.com atau kirimkan mereka file dari
http://groups.yahoo.com/group/XL-mania/files/Promotion/         
:: ------------- ::::::::::::::::::::
Berikan testimoni di : 
http://www.xl-mania.com/2008/06/testimoni-xl-mania.html        
:: ------------- ::::::::::::::::::::
Message lama ada di :
http://groups.yahoo.com/group/XL-mania/messages [perlu yahoo id]
http://www.mail-archive.com/xl-mania@yahoogroups.com

.

__,_._,___

Nenhum comentário:

Arquivo do blog