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

Problems setting a variable to a concatenated string

I need to take the selected values in the l_freq and u_freq, and use them to create a string that will be used as select criteria for another field in the document.  The code I have so far (to build the string, and put the string in a variable) doesn't seem to work.

sub SetLimits()

end sub

When the code gets to the last line, I get an error that says: "Object Required: 'SelectString'

What am I doing wrong?

Oh, and yes, I realize that I can do this in an action, but I ran into problems with things not happening sequentially, so variables were not getting set properly.

Thanks!

dim SelectString

SelectString = ""

ActiveDocument.Fields("l_freq").SelectPossible
ActiveDocument.Fields("u_freq").SelectPossible

set LB = ActiveDocument.getField("l_freq").getSelectedValues()
set UB = ActiveDocument.getField("u_freq").getSelectedValues()

for i = 0 to LB.Count-1
     if i = 0 then SelectString = "("
     SelectString = SelectString & ">=" & LB.item(i).text & "<=" & UB.item(i).text
     if i = LB.Count-1 then
          SelectString = SelectString & ")"
     else
          SelectString = SelectString & "|"
     end if
next

ActiveDocument.Variables("Variable1").setContent SelectString.GetContent.string, true

1 Solution

Accepted Solutions
erichshiino
Partner - Master
Partner - Master

at the last line you don't need the .getcontent.string

ActiveDocument.Variables("Variable1").setContent SelectString, true

I guess this is because this variable  (SelectString) was only exists in this macro environment.

The other case you were working with an object associated with a document variable.

Hope it helps,

Erich

View solution in original post

2 Replies
erichshiino
Partner - Master
Partner - Master

at the last line you don't need the .getcontent.string

ActiveDocument.Variables("Variable1").setContent SelectString, true

I guess this is because this variable  (SelectString) was only exists in this macro environment.

The other case you were working with an object associated with a document variable.

Hope it helps,

Erich

Not applicable
Author

Yep, very much so!  Thanks!