<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Variables in Macros in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896437#M311994</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a macro that will randomly select based on a hard-coded number. I am trying to implement a slider that the user can use to select the number of samples they want to return. If the user selects 15 on the slider, then I want 15 samples to be pulled.The macro works if I hard-code in the number of samples, but I am having difficulty with the slider. I have a variable, vAmountSelect that represents the number from the slider. How should I change the macro to pull the amount from the variable? I thought I could do something like this in the macro, but it isn't working:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sub SelectRandom&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ActiveDocument.Fields("Field").Clear&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While ActiveDocument.Evaluate("getSelectedCount(Field)") &amp;lt; &lt;STRONG&gt;ActiveDocument.Variables("vAmountSelect").getcontent.string&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;val = ActiveDocument.Evaluate("FieldValue('Field', ceil(" &amp;amp; Rnd() _&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp; " * FieldValueCount('Field')))")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ActiveDocument.Fields("Field").ToggleSelect val&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wend&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;End Sub &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Jun 2015 20:55:22 GMT</pubDate>
    <dc:creator />
    <dc:date>2015-06-15T20:55:22Z</dc:date>
    <item>
      <title>Variables in Macros</title>
      <link>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896437#M311994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a macro that will randomly select based on a hard-coded number. I am trying to implement a slider that the user can use to select the number of samples they want to return. If the user selects 15 on the slider, then I want 15 samples to be pulled.The macro works if I hard-code in the number of samples, but I am having difficulty with the slider. I have a variable, vAmountSelect that represents the number from the slider. How should I change the macro to pull the amount from the variable? I thought I could do something like this in the macro, but it isn't working:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sub SelectRandom&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ActiveDocument.Fields("Field").Clear&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While ActiveDocument.Evaluate("getSelectedCount(Field)") &amp;lt; &lt;STRONG&gt;ActiveDocument.Variables("vAmountSelect").getcontent.string&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;val = ActiveDocument.Evaluate("FieldValue('Field', ceil(" &amp;amp; Rnd() _&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp; " * FieldValueCount('Field')))")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ActiveDocument.Fields("Field").ToggleSelect val&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wend&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;End Sub &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2015 20:55:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896437#M311994</guid>
      <dc:creator />
      <dc:date>2015-06-15T20:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Variables in Macros</title>
      <link>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896438#M311995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sub x&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dim doc, fieldSelectedCount, fieldValues, i&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;set doc = ActiveDocument&lt;/P&gt;&lt;P&gt;doc.fields("Field").clear&lt;/P&gt;&lt;P&gt;set fieldValues&amp;nbsp; = doc.fields("Field").getpossiblevalues&lt;/P&gt;&lt;P&gt;fieldSelectedCount = doc.Variables("vAmountSelect").getcontent.string&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for i = 1 to fieldSelectedCount&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; doc.fields("Field").toggleselect fieldValues.item(round((fieldValues.count - 1) * rnd())).text&lt;/P&gt;&lt;P&gt;next&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;end sub&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 12:11:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896438#M311995</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2015-06-16T12:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Variables in Macros</title>
      <link>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896439#M311996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That doesn't seem to be working for me. Can you try updating the QVW that I attached to my original post?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 12:53:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896439#M311996</guid>
      <dc:creator />
      <dc:date>2015-06-16T12:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Variables in Macros</title>
      <link>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896440#M311997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;what makes you think it is not working? I added a msgbox to be sure and it is working. Executed 5 times when the vAmountSelect is 5&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 12:59:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896440#M311997</guid>
      <dc:creator>giakoum</dc:creator>
      <dc:date>2015-06-16T12:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Variables in Macros</title>
      <link>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896441#M311998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I will suggest you create a variable &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;vField =GetSelectedCount(Field)&amp;nbsp;&amp;nbsp; // In UI &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;then get the variable value in macro &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;vField1 &lt;/SPAN&gt;=ActiveDocument.GetVariable("&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;vField &lt;/SPAN&gt;").GetContent.String&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;vAmountSelect1&lt;/SPAN&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;=ActiveDocument.GetVariable("&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;vAmountSelect&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;").GetContent.String&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Now you can use these values for comparison in your condition. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Thanks &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;BKC&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 13:05:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896441#M311998</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-06-16T13:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Variables in Macros</title>
      <link>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896442#M311999</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My example worked - but rnd() could return very similar values which multiplied with the fieldcounter returned a value which is already selected and the selection from a selected field meant this value will be deselected again. Especially in very small field is these effect more noticeable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want avoid such behavior you need an additionally logic within the loop which checked if these value is already selected and skiped them and increased the loop-counter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 13:17:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Variables-in-Macros/m-p/896442#M311999</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2015-06-16T13:17:04Z</dc:date>
    </item>
  </channel>
</rss>

