<?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 use a for ... next loop to set connection strings from an external file in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/use-a-for-next-loop-to-set-connection-strings-from-an-external/m-p/284685#M105835</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks to both of you for your help.&amp;nbsp; The peek(...) worked.&amp;nbsp; I ended up modifying it a bit to use it in the if statement as well since my real connection names were a bit more descriptive than DB1, DB2 and I have to connect to at least half a dozen different databases in some of the dashboards. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for i=0 to NoOfRows('Connections') - 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If peek('varConnection', i, 'Connections')&amp;nbsp; = 'DB1' then &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Let varDB1connect = peek('ConnectString', i, 'Connections');&lt;/P&gt;&lt;P&gt;ELSEIF peek('varConnection', i, 'Connections') = 'DB2' then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Let varDB2connect = peek('ConnectString', i, 'Connections');&lt;/P&gt;&lt;P&gt;Endif;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next i;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your help!!!&lt;/P&gt;&lt;P&gt;Vicky&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 May 2011 20:48:44 GMT</pubDate>
    <dc:creator />
    <dc:date>2011-05-09T20:48:44Z</dc:date>
    <item>
      <title>use a for ... next loop to set connection strings from an external file</title>
      <link>https://community.qlik.com/t5/QlikView/use-a-for-next-loop-to-set-connection-strings-from-an-external/m-p/284682#M105832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Our data source is moving (again) from one IP address to another.&amp;nbsp; I would like to set up a table to manage the connections and store the connection strings in an excel file so that every time this happens I just have to change the connection one place (the spreadsheet) instead of in each dashboard.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The connection string is like " OLEDB CONNECT TO [Provider=SQLOLEDB.1;Persist Security Info=True;User ID= ... "&amp;nbsp; The concept works when I directly assign the connection string to the variable but not when I try to bring it in from a spreadsheet.&amp;nbsp; I'm guessing the problem is in my for loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I thought I could use a for .. next loop to do this but have been unsuccessful.&amp;nbsp; My code looks something like this. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help with what I am doing wrong would be greatly appreciated.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #00ff00;"&gt;// load the connection strings from excel spreadsheet&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Connections:&lt;/P&gt;&lt;P&gt;LOAD &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varConnection,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ConnectString&lt;/P&gt;&lt;P&gt;From Connections.xls&lt;/P&gt;&lt;P&gt;(biff, embedded labels, table is Sheet 1$);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #00ff00;"&gt;//loop through connections to set &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;for i=0 to NoOfRows('Connections') - 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If varConnection = 'DB1' then &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Let varDB1connect = ConnectString;&lt;/P&gt;&lt;P&gt;ELSEIF varConnection = 'DB2' then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Let varDB2connect = ConnectString;&lt;/P&gt;&lt;P&gt;Endif;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next i;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #00ff00;"&gt;//use connection to DB1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;$(varDB1connect)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;DBTable1:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;Load &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;SQL Select * from DB1.TestTable;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #00ff00;"&gt;// use connection to DB2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;$(varDB2connect)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;DBTable2:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;Load&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; D,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; E,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; F;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;SQL Select * from DB2.Test2Table;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 May 2011 19:46:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/use-a-for-next-loop-to-set-connection-strings-from-an-external/m-p/284682#M105832</guid>
      <dc:creator />
      <dc:date>2011-05-09T19:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: use a for ... next loop to set connection strings from an external file</title>
      <link>https://community.qlik.com/t5/QlikView/use-a-for-next-loop-to-set-connection-strings-from-an-external/m-p/284683#M105833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As an alternative, I'd recommend using INCLUDE with a couple of text files instead of this loop:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;$(INCLUDE=\connections\Connect1.txt)&lt;/P&gt;&lt;P&gt;LOAD...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;$(INCLUDE=\connections\Connect2.txt)&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, if you really want to use the loop, then your loop should use function peek(), - something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #00ff00;"&gt;//loop through connections to set &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;for i=0 to NoOfRows('Connections') - 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Let varDB$(i)connect = peek('ConnectString', i, 'Connections');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next i;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This way, for each value of i, you will peek the relevant value...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 May 2011 20:13:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/use-a-for-next-loop-to-set-connection-strings-from-an-external/m-p/284683#M105833</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2011-05-09T20:13:35Z</dc:date>
    </item>
    <item>
      <title>use a for ... next loop to set connection strings from an external file</title>
      <link>https://community.qlik.com/t5/QlikView/use-a-for-next-loop-to-set-connection-strings-from-an-external/m-p/284684#M105834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your loop looks good to me.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should change your &lt;STRONG&gt;Let &lt;/STRONG&gt;statements to &lt;STRONG&gt;Set &lt;/STRONG&gt;and see how that works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If varConnection = 'DB1' then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Set varDB1connect = ConnectString;&lt;/P&gt;&lt;P&gt;ELSEIF varConnection = 'DB2' then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set varDB2connect = ConnectString;&lt;/P&gt;&lt;P&gt;Endif;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Let statement is used to evaluate the statement to the right, while the Set statement is just used to store the info in your variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 May 2011 20:14:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/use-a-for-next-loop-to-set-connection-strings-from-an-external/m-p/284684#M105834</guid>
      <dc:creator>markmccoid</dc:creator>
      <dc:date>2011-05-09T20:14:07Z</dc:date>
    </item>
    <item>
      <title>use a for ... next loop to set connection strings from an external file</title>
      <link>https://community.qlik.com/t5/QlikView/use-a-for-next-loop-to-set-connection-strings-from-an-external/m-p/284685#M105835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks to both of you for your help.&amp;nbsp; The peek(...) worked.&amp;nbsp; I ended up modifying it a bit to use it in the if statement as well since my real connection names were a bit more descriptive than DB1, DB2 and I have to connect to at least half a dozen different databases in some of the dashboards. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for i=0 to NoOfRows('Connections') - 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If peek('varConnection', i, 'Connections')&amp;nbsp; = 'DB1' then &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Let varDB1connect = peek('ConnectString', i, 'Connections');&lt;/P&gt;&lt;P&gt;ELSEIF peek('varConnection', i, 'Connections') = 'DB2' then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Let varDB2connect = peek('ConnectString', i, 'Connections');&lt;/P&gt;&lt;P&gt;Endif;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next i;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your help!!!&lt;/P&gt;&lt;P&gt;Vicky&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 May 2011 20:48:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/use-a-for-next-loop-to-set-connection-strings-from-an-external/m-p/284685#M105835</guid>
      <dc:creator />
      <dc:date>2011-05-09T20:48:44Z</dc:date>
    </item>
  </channel>
</rss>

