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: 
Not applicable

Run a Command Line From Macro

Hello Everyone!

I have to run a Command Line to remove some variables (strings) from an external text file.

I just need to know if it is possible and how to write a Command Line into the Macro.

Thanks in advance

Mirco

5 Replies
rubenmarin

Hi Mirco,check this doc: Useful Qlikview Macros

I think you are searching for the first example.

Not applicable
Author

Hi Ruben,

Thanks for your quick answer,

I wasn't exactly looking for that, because I have many string variables, then I would like to WRITE the command line directly into the Macro in order to set my Variable.

I was also thinking to set some parameters, but I have no idea how to do it.

thanks

Mirco

rubenmarin

Ok, I thought you wanted to execute some bat that does the job.

I didn't done something like this (removing strings from external file) but but still I think it's possible, you can start with:

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile
= "Path\File.Extension"
Set objFile = objFS.OpenTextFile(strFile)


From there you'll need to find the vbscript code to do the work you wanted.


If you want a function to assign values you can use:

Function SetVariable(variable, value)

    Set v = ActiveDocument.Variables(variable)

    v.SetContent value, true

End Function

Hope this helps

Not applicable
Author

I'll try to make it easier for you, there should be some misunderstanding, follow the command line I have to execute:


Path\sbs.exe -c --remove Path\FileName.txt  StringToRemove

StringToRemove is the string variable that i need to remove.


Is there a way to write it into my Macro?

Or is there a way to run a batch file with StringToRemove as a parameter?


thanks

Mirco

rubenmarin

Sorry Mirco, probably I still don't understand the question, I'll make a simple 'show value' example hoping will help you to find the solution...

If you have a batch.bat file than contents:

echo %1

pause

and you create this macro:

SUB CallExample

CreateObject("WScript.Shell").Run("c:\Test\batch.bat MyMessage")

END SUB

Executing CallExample macro from a button in Qv will show 'MyMessage' in cmd windows.

If you need to make the parameter more dynamic you can use a function like:

Function GetVariable(variable)

    Set v = ActiveDocument.Variables(variable)

    GetVariable = v.GetContent.String

End Function

Then you can create the macro:

SUB CallExample

CreateObject("WScript.Shell").Run("c:\Test\batch.bat " & GetVariable("MyStringVar"))

END SUB