Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Defining Variables outside a Sub (marco variable)

Hi all,

Is it possible to define a variable, to be used in sub / macro?

I have a file path hardcoded in a macro, but if I want this to change, I don't really want to search the script for all instances of it.

I know in SAS, SQL etc...I can use a macro variable & state it at the top.  Is this possible with VBScript?

Something like this I want to do:

FilePath = C:\user\document\pictures

Sub

dim fso
Set fso =CreateObject("Scripting.FilesystemObject")
fso.CreateTextFile "FilePath\dummy.txt"

End Sub

1 Solution

Accepted Solutions

Re: Defining Variables outside a Sub (marco variable)

Hi Jammy,

Create a variable in front end and assign the variable in inputbox. You can change the path whenever required,

Untitled.png

You can use below code to fetch the path from front end variable.

Sub Test

Dim fsoh

FilePath = ActiveDocument.GetVariable("vPath").GetContent.String

FileDate =  ActiveDocument.Evaluate("date(Now(), 'DDMMYYYY hhmmss')")

If Right(FilePath,1)<> "\" then

FilePath = FilePath & "\"

End If

Set fso =CreateObject("Scripting.FilesystemObject")

fso.CreateTextFile FilePath & "dummy_" & FileDate & ".txt"

End Sub

Sample attached fro your reference.

3 Replies

Re: Defining Variables outside a Sub (marco variable)

Hi Jammy,

Create a variable in front end and assign the variable in inputbox. You can change the path whenever required,

Untitled.png

You can use below code to fetch the path from front end variable.

Sub Test

Dim fsoh

FilePath = ActiveDocument.GetVariable("vPath").GetContent.String

FileDate =  ActiveDocument.Evaluate("date(Now(), 'DDMMYYYY hhmmss')")

If Right(FilePath,1)<> "\" then

FilePath = FilePath & "\"

End If

Set fso =CreateObject("Scripting.FilesystemObject")

fso.CreateTextFile FilePath & "dummy_" & FileDate & ".txt"

End Sub

Sample attached fro your reference.

Re: Defining Variables outside a Sub (marco variable)

If you want to hardcode the path use below code.

FilePath = "C:\user\document\pictures"

Sub Test

Dim fso

Set fso =CreateObject("Scripting.FilesystemObject")

fso.CreateTextFile FilePath & "\Dummy.txt"

End Sub

Not applicable

Re: Defining Variables outside a Sub (marco variable)

Thank you..... perfect solution & I got it working!

Community Browser