8 Replies Latest reply: May 21, 2015 1:37 AM by balkumar chandel RSS

    How to set a variable to 0 inside macro

    Staffan Johansson

      Hi,

       

      I Run a qlikview file from a batchload where I send a variable=1. This is a trigger that start a reload of the application and also send pdf files. In the end of the macro I would like to set this variable to 0. Because my variable is a OnOpen trigger, and the application runs everytime I forgot to hold Ctrl + Shift down.

        • Re: How to set a variable to 0 inside macro
          Andrei Kaliahin

          Hi,

           

          Try this one:

          set v = ActiveDocument.Variables("Variable1")
          v.SetContent "123",true

           

          Hope this helps.

          Regards,

          Andrei

            • Re: How to set a variable to 0 inside macro
              Staffan Johansson

              I can see that it works, but I dont know where to add it into the script, can you help.

               

              sub  vecka

              ActiveDocument.ClearAll True

              SET x=ActiveDocument.GetVariable("vPdfVariable")
                if x.GetContent.String=x.GetContent.String then
                ActiveDocument.Reload
                ActiveDocument.GetApplication.WaitForIdle

              Set Prods = ActiveDocument.Fields("SäljareNamn").GetPossibleValues

              For i = 0 to Prods.count -1

                  ActiveDocument.Fields("SäljareNamn").Select Prods.item(i).Text

                  DagRapport()

              Next
              ActiveDocument.ClearAll True
              ActiveDocument.Save
                ActiveDocument.GetApplication.Quit

                End if
                
              End Sub

               

              Sub Dagrapport()

              SET x=ActiveDocument.GetVariable("vPdfVariable")
                if x.GetContent.String=x.GetContent.String then
               
               
              set v=ActiveDocument.Fields("SäljareNamn").GetSelectedValues
              set vmail=ActiveDocument.Fields("mail").GetPossibleValues

              set vPrint=ActiveDocument.Fields("SäljareNamn").GetPossibleValues
              End if

              IF(v.Count = 1 and vPrint.item(i).Text = v(i).Text) Then

                  vReport = "RP0"& x.GetContent.String 'Set report

                  vName = (v(i).Text) 'Name of output pdf

              ActiveDocument.PrintReport(vReport), "Bullzip PDF Printer", false 'Printreport
              printReportPDF = "C:\xxxx\pdftest\"&vName&"\" & vName & x.GetContent.String&".pdf" 'Setting outputname
              MyPrintPDFWithBullZip(printReportPDF) 'Call pdf printer
              ActiveDocument.GetApplication.Sleep 10000

              Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
              Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

              Const cdoAnonymous = 0 'Do not authenticate
              Const cdoBasic = 1 'basic (clear-text) authentication
              Const cdoNTLM = 2 'NTLM
              Set objMessage = CreateObject("CDO.Message")
              objMessage.Subject = vName &" " & Date()
              objMessage.From = """QlikViewserver"" <qlikview@xxx.xx>"
              objMessage.To= vmail.item(i).Text
              objMessage.AddAttachment "C:\xxxx\pdftest\"&vName&"\" & vName & x.GetContent.String&".pdf"

              '==This section provides the configuration information for the remote SMTP server.

              objMessage.Configuration.Fields.Item _
              ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

              'Name or IP of Remote SMTP Server
              objMessage.Configuration.Fields.Item _
              ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "xxxxxxxxxxxx"

              'Type of authentication, NONE, Basic (Base64 encoded), NTLM
              objMessage.Configuration.Fields.Item _
              ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

              'Your UserID on the SMTP server
              objMessage.Configuration.Fields.Item _
              ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxxxxxxx"

              'Your password on the SMTP server
              objMessage.Configuration.Fields.Item _
              ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = xxxxxxxxxxx

              'Server port (typically 25)
              objMessage.Configuration.Fields.Item _
              ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = xxx

              'Use SSL for the connection (False or True)
              objMessage.Configuration.Fields.Item _
              ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

              'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
              objMessage.Configuration.Fields.Item _
              ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = xx

              objMessage.Configuration.Fields.Update

              '==End remote SMTP server configuration section==

              objMessage.Send

              Set objMessage = Nothing

              end if
              end sub

              FUNCTION MyPrintPDFWithBullZip (pdfOutputFile)
              set obj = CreateObject("Bullzip.PDFSettings")
              obj.SetValue "Output" , pdfOutputFile
              obj.SetValue "ConfirmOverwrite", "no"
              obj.SetValue "ShowSaveAS", "never"
              obj.SetValue "ShowSettings", "never"
              obj.SetValue "ShowPDF", "no"
              obj.SetValue "RememberLastFileName", "no"
              obj.SetValue "RememberLastFolderName", "no"
              obj.SetValue "ShowProgressFinished", "no"
              obj.SetValue "ShowProgress", "no"
              obj.WriteSettings True

              Set WSHShell = CreateObject("WScript.Shell")

                WSHShell.RegWrite "HKCU\Software\QlikViewPDF\OutputFile", pdfOutputFile, "REG_SZ"
                WSHShell.RegWrite "HKCU\Software\QlikViewPDF\BypassSaveAs", "1", "REG_SZ"

              Set WSHShell = nothing

              End FUNCTION

            • Re: How to set a variable to 0 inside macro
              jagan mohan rao appala

              Hi,

               

              Check below link for lot of such macro code snippets

               

              Useful Qlikview Macros

               

              Hope this helps you.

               

              Regards,

              Jagan.

              • Re: How to set a variable to 0 inside macro
                balkumar chandel

                Hi ,

                 

                Use this code, It will assign variable value as 0 in UI.

                 

                Sub ChangeValue

                         ActiveDocument.Variables("variable").SetContent "0", true       

                        

                End Sub

                 

                 

                Let me know if your requirement is different.

                Thanks

                BKC