0 Replies Latest reply: Sep 17, 2014 9:07 AM by Damien Trippeda RSS

    You're doing it all wrong...Stop using =1

      So in the course of various challenges I've encountered scripting for things in qlikview, the few times I've taken to the forums for answers I've come across the same mistake repeatedly within examples people give. at that is :


      for i = 1 to N...




      When you're using a for statement in qlikviews scripts it starts with the first line as 0, not 1. Every time I've accidentally left my script as i=1, it inevitably produced errors to which I had to return to later to fix. The latest one was an active directory loading script that was having difficulty with the few workarounds for the 1000 line limitation that I've seen online, so I decided to mix two together. Due to the vast size of my company's AD I needed to loop against the first two letters of the name instead of only 1, so I needed to go through every combination aa,ab,ac...z7,z8,z9 . I mindlessly left in the loop statement from a code I copied from the forums and it contained


      For i=1 to (count of values+1)  ... when I would load from this the script skipped every A_ value in the list. simply changing it to i = 0 to (count of values) fixed it and loaded every record. The same thing applies to reading through items in a list box. The first line is 0 and the last is the number of items -1..  So if you have a loop that needs to go through 20 items it should be i = 0 to 19 .. This may be contrary to how we'd normally code loops but seems to be how qlikview treats it. YMMV and maybe it doesnt apply to 100% of loads, but if you have a loop and you're encountering issues try adjusting you're starting number to 0.