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

Set value for mutiple variables

Hi All,

i'm looking for a tips to set a value for more then ten variables.

Now, i'm using a button with action 'set varaible' ten times not really good !!

thanks

1 Solution

Accepted Solutions
jzimolong
Creator II
Creator II

I've attached my .qvw if it helps explain my solution above.  Basically, it loops through each variable in the document and assigns the same value (based on input box) to those that begin with "vSet".  You can play around with the syntax.

View solution in original post

11 Replies
Clever_Anjos
Employee
Employee

Are you setting same value to all of those variables?

Not applicable
Author

Yep

Clever_Anjos
Employee
Employee

You could write a small macro to set all those variable, but using macros is usually a bad idea.

I would stay using 10 actions

Not applicable
Author

hoo noo

i tried :

VAl1;VAL2;VAL3

or

VAl1,VAL2,VAL3

nothing works

jzimolong
Creator II
Creator II

  1. Setup the vbscript macro below and assign to a button action
  2. Make sure your variables have the same first few characters, like "vSet", so macro knows which ones to loop through
  3. Click button, input the value you need to set, then it will loop through them all and set the value

Sub SetVariables

Dim objTempVar, objDestVar, objSourceVar, objSource
varValue = inputBox("Input your value")
varNo = ActiveDocument.GetVariableDescriptions.Count - 1

For i = 0 to varNo
     If Left(ActiveDocument.GetVariableDescriptions.Item(i).Name,4) = "vSet" Then
          set objTempVar = ActiveDocument.GetVariableDescriptions.Item(i)
          varname=Trim(objTempVar.Name)
          Set objSourceVar=ActiveDocument.Variables(varname)
          varcontent=objSourceVar.GetRawContent

          Set objDestVar=ActiveDocument.Variables(varname)
          objDestVar.SetContent varValue,true

     END IF
Next

End Sub

Anonymous
Not applicable
Author

I don't see anything wrong with multiple actions in one button...  In most cases it is better than using macros.

jpapador
Partner - Specialist
Partner - Specialist

Since you are setting the same value you all variables you could just have the button set 1 variable and then have the other 9 variables equal that first one.

Not applicable
Author

I agree, but when you have a lot of variables !! i've got a report with more then 24 variables.

Not applicable
Author

it's sounds like greate !! i'll try this