Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

stabben23
Honored Contributor

How to set a variable to 0 inside macro

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.

Tags (2)
1 Solution

Accepted Solutions
balkumarchandel
Valued Contributor II

Re: How to set a variable to 0 inside macro

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

8 Replies
crusader_
Valued Contributor

Re: How to set a variable to 0 inside macro

Hi,

Try this one:

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

Hope this helps.

Regards,

Andrei

stabben23
Honored Contributor

Re: How to set a variable to 0 inside macro

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

MVP
MVP

Re: How to set a variable to 0 inside macro

Hi,

Check below link for lot of such macro code snippets

Useful Qlikview Macros

Hope this helps you.

Regards,

Jagan.

balkumarchandel
Valued Contributor II

Re: How to set a variable to 0 inside macro

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

stabben23
Honored Contributor

Re: How to set a variable to 0 inside macro

Hi,

All these answer works by them self, but not togheter with my script. The problem is that I don't know where to put it.

The requirement is that it should set the variable=0 when all loops and pdf/mail is ready, last thing before quit the application.

I have test and in some case the code stops because it get 0 in wrong place or doesent get 0 at all if I put it as a single Sub in the bottom. Any Idea, see script above.

stabben23
Honored Contributor

Re: How to set a variable to 0 inside macro

Hi,

I Add ChangeValue() here to get it to work, thaks for putting me in the right direction.

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
ChangeValue()
ActiveDocument.Save
  ActiveDocument.GetApplication.Quit

  End if
  
End Sub

balkumarchandel
Valued Contributor II

Re: How to set a variable to 0 inside macro

so now its working .. Good

balkumarchandel
Valued Contributor II

Re: How to set a variable to 0 inside macro

if you want to set variable after all the work done just include

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


before END SUB


Thanks

BKC

Community Browser