Sunteți pe pagina 1din 4

Function Soles(ByVal Cantidad)

Dim Pesotes, Centavos, Temp


Dim DecimalPlace, Count
Dim origNumLen, origNum
Dim Sep, Moneda
Dim Decimales As Long

Decimales = Round(100 * (Cantidad - Int(Cantidad)), 0) 'extrae la parte decimal

ReDim place(9) As String


place(2) = " MIL "
place(3) = " MILLONES "
place(4) = " BILLONES "
place(5) = " TRILLONES "

Cantidad = Trim(CStr(Cantidad))
origNumLen = Len(Cantidad)
origNum = Cantidad
'Especificar el separador de miles y/o decimales
Sep = "."
'Especificar el tipo de moneda Soles (default)
Moneda = "Soles"

If Sep = "." Then DecimalPlace = InStr(Cantidad, ".")

' Convert Centavos and set Cantidad to currency amount.


If DecimalPlace > 0 Then
Centavos = GetTens(Left(Mid(Cantidad, DecimalPlace + 1) & _
"00", 2))
Cantidad = Trim(Left(Cantidad, DecimalPlace - 1))
End If

Count = 1
Do While Cantidad <> ""
Temp = GetHundreds(Right(Cantidad, 3))
If Temp <> "" Then
If Temp = "UN" And Count > 2 Then
Pesotes = Temp & Left(place(Count), Len(place(Count)) - 3) _
& " " & Pesotes
Else
Pesotes = Temp & place(Count) & Pesotes
End If
End If
If Len(Cantidad) > 3 Then
Cantidad = Left(Cantidad, Len(Cantidad) - 3)
Else
Cantidad = ""
End If
Count = Count + 1
Loop

Select Case Pesotes


Case ""
Pesotes = " (CERO " & Moneda
Case "UN"
Pesotes = " (UN " & Left(Moneda, Len(Moneda) - 1)

Case Else
If origNumLen > 6 And (origNum Mod 1000000) = 0 Then
Pesotes = " (" & Pesotes & " " & "DE " & Moneda
Else
Pesotes = " (" & Pesotes & " " & Moneda
End If
End Select

Select Case Centavos


Case ""
Centavos = " 00/100 M.N.)"
Case Else
If Decimales < 10 Then
Centavos = " 0" & Decimales & "/100 M.N.)"
Else
Centavos = " " & Decimales & "/100 M.N.)"
End If
End Select

Soles = UCase(Trim(Pesotes & Centavos))


End Function

' Convertir rango de numeros del 100 hasta 999 en texto

Private Function GetHundreds(ByVal Cantidad)


Dim Result As String

If Val(Cantidad) = 0 Then Exit Function


Cantidad = Right("000" & Cantidad, 3)

' Convert the hundreds place.


If Mid(Cantidad, 1, 1) <> "0" Then
If Cantidad = "100" Then
Result = "CIEN "
Else
Select Case Mid(Cantidad, 1, 1)
Case 1
Select Case Len(Cantidad)
Case 1
Result = "UN "
Case 3
Result = "CIENTO "
Case 4
Result = ""
Case 6
Result = "CIENTO "
Case 9
Result = "CIENTO "
End Select

Case 2
Result = "DOSCIENTOS "
Case 3
Result = "TRESCIENTOS "
Case 4
Result = "CUATROCIENTOS "
Case 5
Result = "QUINIENTOS "
Case 6
Result = "SEISCIENTOS "
Case 7
Result = "SETECIENTOS "
Case 8
Result = "OCHOCIENTOS "
Case 9
Result = "NOVECIENTOS "
End Select
End If
End If
' Convert the tens and ones place.
If Mid(Cantidad, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(Cantidad, 2))
Else
Result = Result & GetDigit(Mid(Cantidad, 3))
End If

GetHundreds = Result
End Function

' Convertir rango de numeros del 10 hasta 99 en texto

Private Function GetTens(TensText)


Dim Result As String

Result = ""
If Val(Left(TensText, 1)) = 1 Then
Select Case Val(TensText)
Case 10: Result = "DIEZ"
Case 11: Result = "ONCE"
Case 12: Result = "DOCE"
Case 13: Result = "TRECE"
Case 14: Result = "CATORCE"
Case 15: Result = "QUINCE"
Case 16: Result = "DIECISEIS"
Case 17: Result = "DIECISIETE"
Case 18: Result = "DIECIOCHO"
Case 19: Result = "DIECINUEVE"
Case Else
End Select
Else
If Val(Right(TensText, 1)) = 0 Then
Select Case Val(Left(TensText, 1))
Case 2: Result = "VEINTE"
Case 3: Result = "TREINTA"
Case 4: Result = "CUARENTA"
Case 5: Result = "CINCUENTA"
Case 6: Result = "SESENTA"
Case 7: Result = "SETENTA"
Case 8: Result = "OCHENTA"
Case 9: Result = "NOVENTA"
Case Else
End Select
Else
Select Case Val(Left(TensText, 1))
Case 2: Result = "VEINTI"
Case 3: Result = "TREINTA Y "
Case 4: Result = "CUARENTA Y "
Case 5: Result = "CINCUENTA Y "
Case 6: Result = "SESENTA Y "
Case 7: Result = "SETENTA Y "
Case 8: Result = "OCHENTA Y "
Case 9: Result = "NOVENTA Y "
Case Else
End Select
End If

Result = Result & GetDigit _


(Right(TensText, 1))
End If
GetTens = Result
End Function

' Convertir rango de numeros del 1 hasta 9 en texto

Private Function GetDigit(Digit)


Select Case Val(Digit)
Case 1: GetDigit = "UN"
Case 2: GetDigit = "DOS"
Case 3: GetDigit = "TRES"
Case 4: GetDigit = "CUATRO"
Case 5: GetDigit = "CINCO"
Case 6: GetDigit = "SEIS"
Case 7: GetDigit = "SIETE"
Case 8: GetDigit = "OCHO"
Case 9: GetDigit = "NUEVE"
Case Else: GetDigit = ""
End Select
End Function

S-ar putea să vă placă și