Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
AWS Degraded - You may experience Community slowness, timeouts, or trouble accessing: LATEST HERE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Pass values of a list box or field to an array

Good day,

I'm just wondering can i pass the values of a list box to an array then make a loop statement so that i dont have to select the field value one by one.

Hope you can help me on this...

error loading image

7 Replies
deepakk
Partner - Specialist III
Partner - Specialist III

hi,

You can do it at macro level.

rem ** show each possible value in list box **

set LB = ActiveDocument.GetSheetObject("LB01")

boxvalues=LB.GetPossibleValues

for i = lbound(boxvalues) to ubound(boxvalues)

msgbox(boxvalues(i))

next

Hope this helps


Not applicable
Author

what if i want to pass it to a variable instead of a message box..??

cause i will use it in my set analysis..thanks!

deepakk
Partner - Specialist III
Partner - Specialist III

HI,

add this code instead of message box

set v = ActiveDocument.Variables("Variable1") // you can write this code before for loop

v.SetContent "123",true /// inside for loop

Instead of 123 add box value



Not applicable
Author

when i use a text object to check if the variable got all the values in the list box, the text object shows " - "

deepakk
Partner - Specialist III
Partner - Specialist III

text box and variable cant store array value it can show only single value

if you want to store it in a variable and use it in set analysis then you should convert data into string

a= "BrandA",BrandB",BrandC"

us this expression

var = & """ & var & boxvalue & """ this should be written inside for loop

and after next

v.SetContent var ,true

Not applicable
Author

I encountered a syntax error on this part: var = & """ & var & BoxValue & """

can you give me the whole process cause i'm not that familiar with macros..thanks!

Miguel_Angel_Baeyens

Hi,

I'd rather use the concat() function (use first ina textbox to see if this does):

=chr(39) & Concat(DISTINCT Brand, chr(39) & ',' & chr(39) ) & chr(39)


Now in the load script you can use a for each loop

Brands:LOAD * INLINE [BrandBrandABrandVBrandFBrandG]; BrandArrayTable: // Building the array LOAD RowNo() AS No, CONCAT(DISTINCT Brand, chr(39) & ', ' & chr(39)) AS BrandArrayRESIDENT Brands; LET vAllBrands = chr(39) & Peek('BrandArray') & chr(39); FOR EACH vBrand IN $(vAllBrands) TRACE $(vBrand);NEXT