VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Returns the text for any integer number less 1,000,000,000 in spanish language

by Francisco Castillo (2 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 9th October 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Returns the text for any integer number less 1,000,000,000 in spanish language

Rate Returns the text for any integer number less 1,000,000,000 in spanish language



' By Francisco Castillo - september 2000.
' Devuelve la representación textual del valor del nú-
' mero ENTERO que se pasa como argumento, (100 =
' "Cien"). El parámetro "masculino" será True cuando deban
' ponerse terminaciones masculinas,(210 = doscientOs
' diez), y False en caso contrario, (320 = trescientAs
' veinte). El valor máximo del número es de
'                      999.999.999
    If number = 0 Then
        NumberToString = "Cero"
        Exit Function
    End If
    If number < 0 Then             ' Hacerlo positivo,
        number = number * -1
    End If
    X = CStr(Fix(number))          ' ...entero,
    Do While Len(X) < 9         ' ...y de 9 cifras.
        X = "0" & X
    Loop
    a = ""
' Grupos de 3 cifras, de atrás hacia adelante:
    For n = 7 To 1 Step -3
' ¿El grupo actual es cero?:
        If CInt(Mid(X, n, 3)) <> 0 Then
' No.
' Tratar casos especiales decena:
            Select Case CInt(Mid(X, n + 1, 2))
                Case 10
                    a = "diez " & a
                Case 11
                    a = "once " & a
                Case 11
                    a = "once " & a
                Case 12
                    a = "doce " & a
                Case 13
                    a = "trece " & a
                Case 14
                    a = "catorce " & a
                Case 15
                    a = "quince " & a
                Case 16
                    a = "dieciseis " & a
                Case 17
                    a = "diecisiete " & a
                Case 18
                    a = "dieciocho " & a
                Case 19
                    a = "diecinueve " & a
                Case 20
                    a = "veinte " & a
                Case 21
                    If n > 1 Then
                        a = "veintiun$ " & a
                    Else
                        a = "veintiun " & a
                    End If
                Case 22
                    a = "veintidos " & a
                Case 23
                    a = "veintitrés " & a
                Case 24
                    a = "veinticuatro " & a
                Case 25
                    a = "veinticinco " & a
                Case 26
                    a = "veintiseis " & a
                Case 27
                    a = "veintisiete " & a
                Case 28
                    a = "veintiocho " & a
                Case 29
                    a = "veintinueve " & a
                Case Else
' Restantes casos; traducir unidad:
                    Select Case CInt(Mid(X, n + 2, 1))
                        Case 0
                        Case 1
                            Select Case n
                                Case 7
                                    a = "y un$ " & a
                                Case 4
                                    If masculino Then
                                        a = "y un " & a
                                    Else
                                        a = "y una " & a
                                    End If
                                Case 1
                                    a = "y un " & a
                            End Select
                        Case 2
                            a = "y dos " & a
                        Case 3
                            a = "y tres " & a
                        Case 4
                            a = "y cuatro " & a
                        Case 5
                            a = "y cinco " & a
                        Case 6
                            a = "y seis " & a
                        Case 7
                            a = "y siete " & a
                        Case 8
                            a = "y ocho " & a
                        Case 9
                            a = "y nueve " & a
                    End Select
' Traducir decena:
                    Select Case CInt(Mid(X, n + 1, 1))
                        Case 0
                        Case 3
                            a = "treinta " & a
                        Case 4
                            a = "cuarenta " & a
                        Case 5
                            a = "cincuenta " & a
                        Case 6
                            a = "sesenta " & a
                        Case 7
                            a = "setenta " & a
                        Case 8
                            a = "ochenta " & a
                        Case 9
                            a = "noventa " & a
                    End Select
            End Select
' Prever caso "ciento y tres":
            If Left(a, 1) = "y" Then
                a = Right(a, Len(a) - 2)
            End If
' Traducir centena:
            Select Case CInt(Mid(X, n, 1))
                Case 0
                Case 1
                    If CInt(Mid(X, n + 1, 2)) = 0 Then
                        a = "cien " & a
                    Else
                        a = "ciento " & a
                    End If
                Case 2
                    a = "doscient$s " & a
                Case 3
                    a = "trescient$s " & a
                Case 4
                    a = "cuatrocient$s " & a
                Case 5
                    a = "quinient$s " & a
                Case 6
                    a = "seiscient$s " & a
                Case 7
                    a = "setecient$s " & a
                Case 8
                    a = "ochocient$s " & a
                Case 9
                    a = "novecient$s " & a
                
            End Select
        End If
' Poner terminación del grupo anterior:
' Puede haber quedado "y tres":
        If Left(a, 1) = "y" Then
            a = Right(a, Len(a) - 2)
        End If
' Millones:
        If n = 4 Then
            If CInt(Left(X, 3)) = 1 Then
                a = "millón " & a
            Else
                If CInt(Left(X, 3)) <> 0 Then
                    a = "millones " & a
                End If
            End If
        Else
            If n = 7 Then
' Miles:
                If CInt(Mid(X, 4, 3)) = 1 Then
                    a = "mil " & a
                Else
                    If CInt(Mid(X, 4, 3)) <> 0 Then
                        a = "mil " & a
                    End If
                End If
            End If
        End If
' Traducir género, "$" en el texto. Para el grupo de los
' millones, se traduce siempre por masculino:
        If n = 1 Then
            masculino = True
        End If
        Posic = 1
        Do While Posic <> 0
            Posic = InStr(a, "$")
            If Posic <> 0 Then
                ante = Left(a, Posic - 1)
                post = Right(a, Len(a) - Posic)
                If masculino Then
                    a = ante & "o" & post
                Else
                    a = ante & "a" & post
                End If
            End If
        Loop
    Next n
' Caso especial: puede haber quedado "unx mil "
    If Left(a, 7) = "un mil " Then
        a = Right(a, Len(a) - 3)
    Else
        If Left(a, 8) = "una mil " Then
            a = Right(a, Len(a) - 4)
        End If
    End If
' Inicial en mayúsculas:
    NumberToString = Trim(UCase(Left(a, 1)) & Right(a, Len(a) - 1))
End Function



Download this snippet    Add to My Saved Code

Returns the text for any integer number less 1,000,000,000 in spanish language Comments

No comments have been posted about Returns the text for any integer number less 1,000,000,000 in spanish language. Why not be the first to post a comment about Returns the text for any integer number less 1,000,000,000 in spanish language.

Post your comment

Subject:
Message:
0/1000 characters