Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
gfarrell
Partner - Contributor III
Partner - Contributor III

Macro to make a select on list of values from an input Field

Hi all,

I am trying to come up with a macro to make a selection from a delimited list of input fields in a variable.

The goal is for a user to paste a list of items into an input field/variable and to execute a selection from that list. I am haflfway there in that I can create the delimited list from the input field.

Does anyone have macro to the would parse a delimited variable and execute something like a select/toogleselect on those values.

Regards,

gdfarrell

6 Replies
boorgura
Specialist
Specialist

Please try out to parse the delimited variable using the substring function and store them into an array (say array named <varArray>).

then use ActiveDocument.Fields("fieldName").SelectValues varArray

This should work.

Please let me know if it works.

gfarrell
Partner - Contributor III
Partner - Contributor III
Author

Rocky,

Your point of storing the values in an array got me going in the right direction. The selectvalues didn't seem to work. This is what I ended up with :

sub SelectItems

vList = Activedocument.fields("vItemList").getcontent.string

vArray = Split(vList, ",")

ActiveDocument.fields("Field1").Select vArray(0)

For i = 1 to UBound(vArray)

ActiveDocument.fields("Field1").ToggleSelect vArray(i)

Next

End Sub

Greg

Much appreciated



Not applicable

Hi, I have the same situation, this answer is usefull for me but Im trying to select 5000 values from my list and is so slow, somebody knows how do it faster ??

johnw
Champion III
Champion III


Hamlet wrote:Hi, I have the same situation, this answer is usefull for me but Im trying to select 5000 values from my list and is so slow, somebody knows how do it faster ??


Are you on version 9 or above? If so, you can do this using an action instead of a macro, and I'm guessing it would be significantly faster, though I've done no performance testing to back that guess up.

In the attached example, the list is "delimited" by a carriage return, so it's assuming that the user has a vertical list of values that they're cutting and pasting into the input box. But the example could be changed slightly to delimit by commas or whatever you want. There's a replace() in the search string for the action where it's converting the carriage return. If you were using a comma-delimited list, for instance, just replace the carriage return with a comma, I believe.

Oh, in case it's confusing, the trigger for the action is a variable event trigger, so settings, document properties, triggers, variable event triggers, List, OnInput, Edit Actions(s).

Not applicable

Hi Jhon,

Thanks for your help. I'm using Qlikview 8.5 reason why i don't have trigger option, however i used your script to make a macro like this.

Sub Filter

set v = ActiveDocument.Variables("FiltroExt2")
strVariable = v.GetContent.String

vOptions = "'" & replace(strVariable, chr(10), "','") & "'"
Set C=ActiveDocument.Getfield("MyField")
C.Select "=match(MyField," & vOptions & ")"

End Sub

The performance really getting better

Thanks a lot.

Rgds

montubhardwaj
Specialist
Specialist


Works nicely... Very nice logic John... You Rock