VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code convert numbers to letters in spanish for use in your applications (currency format) Func

by Edmundo Mendoza / mundini (1 Submission)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 10th June 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code convert numbers to letters in spanish for use in your applications (currency format) Funcion para conertir numeros a letras en

API Declarations


'Only send to the function the numer and it will return the string

Rate This code convert numbers to letters in spanish for use in your applications (currency format) Func



  Dim Unidades(9), Decenas(9), Centenas(9), Especial(5), Especial2(9)
  Dim Ind_Num, Ind_ant, str1, rValue As String
  Dim ind1 As Integer
  rValue = Format(dblValue, "#########.00")
 
  Unidades(1) = "UN"
  Unidades(2) = "DOS"
  Unidades(3) = "TRES"
  Unidades(4) = "CUATRO"
  Unidades(5) = "CINCO"
  Unidades(6) = "SEIS"
  Unidades(7) = "SIETE"
  Unidades(8) = "OCHO"
  Unidades(9) = "NUEVE"
  
  Decenas(1) = "DIEZ"
  Decenas(2) = "VEINTE"
  Decenas(3) = "TREINTA"
  Decenas(4) = "CUARENTA"
  Decenas(5) = "CINCUENTA"
  Decenas(6) = "SESENTA"
  Decenas(7) = "SETENTA"
  Decenas(8) = "OCHENTA"
  Decenas(9) = "NOVENTA"

  Centenas(1) = "CIENTO"
  Centenas(2) = "DOSCIENTOS"
  Centenas(3) = "TRESCIENTOS"
  Centenas(4) = "CUATROCIENTOS"
  Centenas(5) = "QUINIENTOS"
  Centenas(6) = "SEISCIENTOS"
  Centenas(7) = "SETECIENTOS"
  Centenas(8) = "OCHOCIENTOS"
  Centenas(9) = "NOVECIENTOS"
  
  Especial(1) = "ONCE"
  Especial(2) = "DOCE"
  Especial(3) = "TRECE"
  Especial(4) = "CATORCE"
  Especial(5) = "QUINCE"
  
  Especial2(1) = "VEINTIUNO"
  Especial2(2) = "VEINTIDOS"
  Especial2(3) = "VEINTITRES"
  Especial2(4) = "VEINTICUATRO"
  Especial2(5) = "VEINTICINCO"
  Especial2(6) = "VEINTISEIS"
  Especial2(7) = "VEINTISIETE"
  Especial2(8) = "VEINTIOCHO"
  Especial2(9) = "VEINTINUEVE"

  str1 = "" ' & Format((dblValue - Int(dblValue)) * 100, "00") & "/100 pesos"
  importe1 = Mid(rValue, 1, Len(rValue) - 3)
  Ind_Num = ""
  Ind_ant = ""
  For ind1 = Len(importe1) To 1 Step -1
    Ind_ant = Ind_Num
    Ind_Num = Mid(importe1, ind1, 1)
    ind2 = Len(importe1) - ind1 + 1
    Select Case ind2
    'Unidades , Miles y Millones
      Case 1, 4, 7
        If (ind1 - 1) > 0 Then
          If (Mid(importe1, ind1 - 1, 1) = 1 And Mid(importe1, ind1, 1) > 5) Or Mid(importe1, ind1 - 1, 1) > 2 Or Mid(importe1, ind1 - 1, 1) = 0 Then
            If ind2 = 1 Then
              str1 = str1 & Unidades(Ind_Num)
            Else
              If ind2 = 4 Then
                str1 = Unidades(Ind_Num) & " MIL " & str1
              Else
                If Unidades(Ind_Num) = "UN" Then
                  str1 = Unidades(Ind_Num) & " MILLON " & str1
                Else
                  str1 = Unidades(Ind_Num) & " MILLONES " & str1
                End If
              End If
            End If
          End If
        Else
          If ind2 = 1 Then
            str1 = str1 & Unidades(Ind_Num)
          Else
            If ind2 = 4 Then
              str1 = Unidades(Ind_Num) & " MIL " & str1
            Else
              If Unidades(Ind_Num) = "UN" Then
                str1 = Unidades(Ind_Num) & " MILLON " & str1
              Else
                str1 = Unidades(Ind_Num) & " MILLONES " & str1
              End If
            End If
          End If
        End If
'Decenas Diezmiles Diezmillones
      Case 2, 5, 8
        munits = ""
        If ind2 = 5 Then munits = " MIL "
        If ind2 = 8 Then munits = " MILLONES "
        
        If Ind_Num = 1 And Ind_ant < 6 Then
          str1 = Especial(Ind_ant) & munits & str1
        Else
          If Ind_Num = 2 Then
            str1 = Especial2(Ind_ant) & munits & str1
          Else
            If Ind_Num > 0 And Ind_ant > 0 Then
              str1 = Decenas(Ind_Num) & " y " & str1
            Else
              str1 = Decenas(Ind_Num) & str1
            End If
          End If
        End If
        
'Centenas Cienmiles
       Case 3, 6, 9
       
         str1 = Centenas(Ind_Num) & " " & str1
        
    End Select
  Next
  NumToText = str1 & " PESOS " & Format((dblValue - Int(dblValue)) * 100, "00") & "/100"
End Function


Download this snippet    Add to My Saved Code

This code convert numbers to letters in spanish for use in your applications (currency format) Func Comments

No comments have been posted about This code convert numbers to letters in spanish for use in your applications (currency format) Func. Why not be the first to post a comment about This code convert numbers to letters in spanish for use in your applications (currency format) Func.

Post your comment

Subject:
Message:
0/1000 characters