Buscar este blog

lunes, 13 de junio de 2011

Función para leer números detallada

He recibido varias consultas sobre el tema, sobre todo pidiéndome el contenido de la función.
Para los que entiendan sobre macros les dejo el texto completo (tiene 2 procedimientos):

Function NOMBRE(x)
xuni = "uno         dos         tres        cuatro      cinco       " + _
       "seis        siete       ocho        nueve       diez        " + _
       "once        doce        trece       catorce     quince      " + _
       "dieciséis   diecisiete  dieciocho   diecinueve  veinte      " + _
       "veintiuno   veintidós   veintitrés  veinticuatroveinticinco " + _
       "veintiséis  veintisiete veintiocho  veintinueve "
xdec = "treinta  cuarenta cincuentasesenta  setenta  ochenta  noventa"
xcent = "dosc   tresc  cuatrocquin   seisc  setec  ochoc   novec"
NOMBRE = ""
uni = Right(x, 2)
If uni < 30 And uni > 0 Then
    NOMBRE = Trim(Mid(xuni, 12 * (uni - 1) + 1, 12))
End If
If uni > 29 Then
    dec = Left(uni, 1)
    uni = Right(uni, 1)
    NOMBRE = Trim(Mid(xdec, 9 * (dec - 3) + 1, 9))
    If uni <> 0 Then
        NOMBRE = NOMBRE + " y " + Trim(Mid(xuni, 12 * (uni - 1) + 1, 12))
    End If
End If
cent = Int(x / 100)
If cent = 1 Then
    NOMBRE = "ciento " + NOMBRE
End If
If x = 100 Then
    NOMBRE = "cien"
End If
If cent > 1 Then
    NOMBRE = Trim(Mid(xcent, 7 * (cent - 2) + 1, 7)) + "ientos " + NOMBRE
End If
End Function

Function ALETRAS(x)
ALETRAS = ""
millones = Right(Int(x / 1000000), 3)
parte1 = Right(Int(x), 3)
PARTE2 = Right(Int(x / 1000), 3)
If millones = 1 Then ALETRAS = NOMBRE(millones) + " millón "
If millones > 1 Then ALETRAS = NOMBRE(millones) + " millones "
If PARTE2 = 1 Then ALETRAS = ALETRAS + " un mil "
If PARTE2 > 1 Then ALETRAS = ALETRAS + NOMBRE(PARTE2) + " mil "
ALETRAS = ALETRAS + NOMBRE(parte1)
centavos = (Round(x, 2) - Int(x)) * 100
centavos = Right(Round(centavos, 0), 2)
concon = ""
If PARTE2 > 0 Then concon = " con "
If centavos > 0 Then ALETRAS = ALETRAS + concon + centavos + " centavos"
ALETRAS = ALETRAS + "."
End Function

No hay comentarios:

Publicar un comentario

Si quieres dejar algún comentario puedes hacerlo aquí: