Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
javier_florian
Creator III
Creator III

Debug to Macro

Hi Everyone,

Can you help me to make a debug to the macro attached? I need spell number (money) over a pdf report, but I don't find a way.

Thanks in advanced.

3 Replies
Alejandro_Hernández
Former Employee
Former Employee

try this :

Option Explicit

'Main Function

Function SpellNumber(ByVal MyNumber)

    Dim Dollars, Cents, Temp

    Dim DecimalPlace, Count

    ReDim Place(9)

    Place(2) = " Miles "

    Place(3) = " Millones "

    Place(4) = " Billones "

    Place(5) = " Trillones "

    ' String representation of amount.

    MyNumber = Trim(CStr(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 = "No Dollars"

        Case "One"

            Dollars = "Un Peso"

         Case Else

            Dollars = Dollars & " PCOL"

    End Select

    Select Case Cents

        Case ""

            Cents = " and No Cents"

        Case "One"

            Cents = " and One Cent"

              Case Else

            Cents = " and " & Cents & " Centavos"

    End Select

    SpellNumber = Dollars & Cents

End Function

     

' Converts a number from 100-999 into text

Function GetHundreds(ByVal MyNumber)

    Dim Result

    If CInt(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)) & " Cientos "

    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

    Result = ""           ' Null out the temporary function value.

    If CInt(Left(TensText, 1)) = 1 Then   ' If value between 10-19...

        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 value between 20-99...

        Select Case Cint(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

        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 CInt(Digit)

        Case 1: GetDigit = "Uno"

        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

Even though it seems you want to do this in spanish and it's not working at 100%. This one seems to work better:

Function Num_texto(Numero)

    Dim Texto

    Dim Millones

    Dim Miles

    Dim Cientos

    Dim Decimales

    Dim Cadena

    Dim CadMillones

    Dim CadMiles

    Dim CadCientos

    Texto = Numero

    Texto = FormatNumber(Texto, 2)

    Texto = Right(Space(14) & Texto, 14)

    Millones = Mid(Texto, 1, 3)

    Miles = Mid(Texto, 5, 3)

    Cientos = Mid(Texto, 9, 3)

    Decimales = Mid(Texto, 13, 2)

    CadMillones = ConvierteCifra(Millones, 1)

    CadMiles = ConvierteCifra(Miles, 1)

    CadCientos = ConvierteCifra(Cientos, 0)

    If Trim(CadMillones) > "" Then

        If Trim(CadMillones) = "UN" Then

            Cadena = CadMillones & " MILLON"

        Else

            Cadena = CadMillones & " MILLONES"

        End If

    End If

    If Trim(CadMiles) > "" Then

        Cadena = Cadena & " " & CadMiles & " MIL"

    End If

    If Trim(CadMiles & CadCientos) = "UN" And Not Cientos = "000" Then

        Cadena = Cadena & "UNO CON " & Decimales & "/100"

    Else

        If Miles & Cientos = "000000" Then

            Cadena = Cadena & " " & Trim(CadCientos) & " " & Decimales & "/100"

        Else

            Cadena = Cadena & " " & Trim(CadCientos) & " " & Decimales & "/100"

        End If

    End If

    Num_texto = Trim(Cadena)

End Function

'-----------------------------------------------------------------

Function ConvierteCifra(Texto, SW)

    Dim Centena

    Dim Decena

    Dim Unidad

    Dim txtCentena

    Dim txtDecena

    Dim txtUnidad

    Centena = Mid(Texto, 1, 1)

    Decena = Mid(Texto, 2, 1)

    Unidad = Mid(Texto, 3, 1)

    Select Case Centena

        Case "1"

            txtCentena = "CIEN"

            If Decena & Unidad <> "00" Then

                txtCentena = "CIENTO"

            End If

        Case "2"

            txtCentena = "DOSCIENTOS"

        Case "3"

            txtCentena = "TRESCIENTOS"

        Case "4"

            txtCentena = "CUATROCIENTOS"

        Case "5"

            txtCentena = "QUINIENTOS"

        Case "6"

            txtCentena = "SEISCIENTOS"

        Case "7"

            txtCentena = "SETECIENTOS"

        Case "8"

            txtCentena = "OCHOCIENTOS"

        Case "9"

            txtCentena = "NOVECIENTOS"

    End Select

    Select Case Decena

        Case "1"

            txtDecena = "DIEZ"

            Select Case Unidad

                Case "1"

                    txtDecena = "ONCE"

                Case "2"

                    txtDecena = "DOCE"

                Case "3"

                    txtDecena = "TRECE"

                Case "4"

                    txtDecena = "CATORCE"

                Case "5"

                    txtDecena = "QUINCE"

                Case "6"

                    txtDecena = "DIECISEIS"

                Case "7"

                    txtDecena = "DIECISIETE"

                Case "8"

                    txtDecena = "DIECIOCHO"

                Case "9"

                    txtDecena = "DIECINUEVE"

            End Select

        Case "2"

            txtDecena = "VEINTE"

            If Unidad <> "0" Then

                txtDecena = "VEINTI"

            End If

        Case "3"

            txtDecena = "TREINTA"

            If Unidad <> "0" Then

                txtDecena = "TREINTA Y "

            End If

        Case "4"

            txtDecena = "CUARENTA"

            If Unidad <> "0" Then

                txtDecena = "CUARENTA Y "

            End If

        Case "5"

            txtDecena = "CINCUENTA"

            If Unidad <> "0" Then

                txtDecena = "CINCUENTA Y "

            End If

        Case "6"

            txtDecena = "SESENTA"

            If Unidad <> "0" Then

                txtDecena = "SESENTA Y "

            End If

        Case "7"

            txtDecena = "SETENTA"

            If Unidad <> "0" Then

                txtDecena = "SETENTA Y "

            End If

        Case "8"

            txtDecena = "OCHENTA"

            If Unidad <> "0" Then

                txtDecena = "OCHENTA Y "

            End If

        Case "9"

            txtDecena = "NOVENTA"

            If Unidad <> "0" Then

                txtDecena = "NOVENTA Y "

            End If

    End Select

    If Decena <> "1" Then

        Select Case Unidad

            Case "1"

                If SW Then

                    txtUnidad = "UN"

                Else

                    txtUnidad = "UNO"

                End If

            Case "2"

                txtUnidad = "DOS"

            Case "3"

                txtUnidad = "TRES"

            Case "4"

                txtUnidad = "CUATRO"

            Case "5"

                txtUnidad = "CINCO"

            Case "6"

                txtUnidad = "SEIS"

            Case "7"

                txtUnidad = "SIETE"

            Case "8"

                txtUnidad = "OCHO"

            Case "9"

                txtUnidad = "NUEVE"

        End Select

    End If

    ConvierteCifra = txtCentena & " " & txtDecena & txtUnidad

End Function

javier_florian
Creator III
Creator III
Author

Can apply a macro in a pivot table expression?

marcus_sommer

You could per right click on the qlik-logo within Help --> About ... but be careful with these settings:

- Marcus