Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Variable Overview - Edit Script

Hi Guys,

I have created a new QV document and wanted to export my variable overviews from another document. I however, thought that it would be easier in the future if I could somehow define these variable names in the edit script.

Is there a way to do this?

Thanks,

Byron

1 Solution

Accepted Solutions
IAMDV
Luminary Alumni
Luminary Alumni

Byron - Please use the below VBA Code from Excel.

Tim Benoit has provided this solution!

http://qlikviewmaven.blogspot.com/2008/11/listing-all-variables-and-contents.html

Sub List_QV_Variables()
'This Excel macro will ask you to select a QlikView Report File and
'then it will put the variable names and contents into your current worksheet
'--Tim Benoit, Nov 2008
Dim oQV, oRpt, oVars, oTempVar, oThisVar, qv_fn

'Get the QlikView report pathname
qv_fn = Application.GetOpenFilename("QlikView Report File (.),*.*", , "Select a QlikView .qvw Report File", False)
If qv_fn = 0 Then
Exit Sub
End If

'Write out some heading text
ActiveSheet.Cells(1, 1).Formula = "QlikView Variables List"
ActiveSheet.Cells(2, 1).Formula = "Report pathname:"
ActiveSheet.Cells(2, 2).Formula = qv_fn
ActiveSheet.Cells(3, 1).Formula = "Variable Name"
ActiveSheet.Cells(3, 2).Formula = "Variable Content"

'Open the QlikView report file
Set oQV = CreateObject("QlikTech.QlikView")
Set oRpt = oQV.OpenDoc(qv_fn)
Set oVars = oRpt.GetVariableDescriptions
'Loop through the variables
For i = 0 To oVars.Count - 1
Set oTempVar = oVars.Item(i)
varname = Trim(oTempVar.Name)
Set oThisVar = oRpt.Variables(varname)
varcontent = oThisVar.GetRawContent
'Write data into worksheet cells
ActiveSheet.Cells(i + 4, 1).NumberFormat = "@"
ActiveSheet.Cells(i + 4, 1).Formula = varname
ActiveSheet.Cells(i + 4, 2).NumberFormat = "@"
ActiveSheet.Cells(i + 4, 2).Formula = varcontent
Next

'Close QlikView
oRpt.CloseDoc
oQV.Quit
End Sub

View solution in original post

6 Replies
IAMDV
Luminary Alumni
Luminary Alumni

Byron - Please use the below VBA Code from Excel.

Tim Benoit has provided this solution!

http://qlikviewmaven.blogspot.com/2008/11/listing-all-variables-and-contents.html

Sub List_QV_Variables()
'This Excel macro will ask you to select a QlikView Report File and
'then it will put the variable names and contents into your current worksheet
'--Tim Benoit, Nov 2008
Dim oQV, oRpt, oVars, oTempVar, oThisVar, qv_fn

'Get the QlikView report pathname
qv_fn = Application.GetOpenFilename("QlikView Report File (.),*.*", , "Select a QlikView .qvw Report File", False)
If qv_fn = 0 Then
Exit Sub
End If

'Write out some heading text
ActiveSheet.Cells(1, 1).Formula = "QlikView Variables List"
ActiveSheet.Cells(2, 1).Formula = "Report pathname:"
ActiveSheet.Cells(2, 2).Formula = qv_fn
ActiveSheet.Cells(3, 1).Formula = "Variable Name"
ActiveSheet.Cells(3, 2).Formula = "Variable Content"

'Open the QlikView report file
Set oQV = CreateObject("QlikTech.QlikView")
Set oRpt = oQV.OpenDoc(qv_fn)
Set oVars = oRpt.GetVariableDescriptions
'Loop through the variables
For i = 0 To oVars.Count - 1
Set oTempVar = oVars.Item(i)
varname = Trim(oTempVar.Name)
Set oThisVar = oRpt.Variables(varname)
varcontent = oThisVar.GetRawContent
'Write data into worksheet cells
ActiveSheet.Cells(i + 4, 1).NumberFormat = "@"
ActiveSheet.Cells(i + 4, 1).Formula = varname
ActiveSheet.Cells(i + 4, 2).NumberFormat = "@"
ActiveSheet.Cells(i + 4, 2).Formula = varcontent
Next

'Close QlikView
oRpt.CloseDoc
oQV.Quit
End Sub

colinh
Partner - Creator II
Partner - Creator II

Byron, you can use the set function in your script to define variable values. So, for example, if you have a variable called vMaxYear in your document that is defined as =max(Year), in your script you can have

set vMaxYear = "=max(Year)";

This will create the variable in your document the same as if you had created it through the front end.

The only time I have run into problems with this is if the variables themselves contain quotes, that can get tricky.

Colin.

Not applicable
Author

Thanks DV, that gives me what I need for now. However, what I wanted to know is if there is a way that I could write this in the edit script, instead of using vba code. Just curious

Colin, thanks for your reply. I do not want to define the values in the edit script but actually create the variables there, so when I go to variable overview I see it listed there. I can then use sliders or whatever to define the value 🙂

Thanks guys,

Byron

colinh
Partner - Creator II
Partner - Creator II

If you use a let or a set statement in your script, that will create a variable, that will then appear in the variable overview. You can define the variable at the same time as you create it, either by making it an expression, like in my previous example, or by giving it a value, e.g., let vNumber = 1, and then having a slider or input box in your document to change it.

Try a simple let statement in a script, without having created a variable through the variable overview, and you will see that variable appear in the variable overview after you have reloaded.

Colin.

Not applicable
Author

@Colin, fantastic, exactly what I wanted and so easy 🙂 A noob like me likes easy things like this.

Shot dude

Byron

IAMDV
Luminary Alumni
Luminary Alumni

Excellent Colin. That's excatly the same I do... when I declare variables. This enables full control compared to using only Variable Overiew (GUI) window.

Byron - thanks for the points. I am sure Tim's VBA code will be very helpful. I'll work on writing samething in VB Script using QV API. I'll post here if I can get this done.

Cheers - DV