I want to Loop through each row in a table, set variables to the values of each row in order to do some repetitive processing. Seems like a simple construct that would be used often. Here is what I thought would work, but for some reason the data coming back doesn't seem to match across the column for each row returned, and as I work through index by third iteration I'm getting nulls on the second column.
It works perfect without a third parameter of table name, but for grins I tried adding this third parameter...it didn't break anything, but the result was the creation of a new variable of the same name as table that would get set to NULL on each peek.
Daniel's suggestion worked as is, although seem tables have origin 0 not 1 in QV, so had to change my FOR:
NumRows=NoOfRows('BOX'); FORi=0 to$(NumRows)-1 LETvBox=Peek('BOXName',$(i)); LETvVolCnt=peek('VOLCnt',$(i)); //do some repetitive stuff.... NEXT;
I might be over thinking it, but it might be important when you have the same value repeating multiple times in different tables rows, and possibly the same field present in multiple tables. then, when you specify
peek ('field', index)
it becomes unclear what the index should represent - the value index in a field list, or a row in a table? ...what table?
the two formats might work identically in simple cases when the field only exists in the same table, and when values are fairly unique.
Well Oleg, thought you might be onto something here. Once I put an SQL Select into the loop, the "Peeks" returned NULL on the second iteration as though somehow the SQL statement cleared the values from the Inline Table. Started thinking your qualification with the third parameter might be the ticket, but didn't make a difference
Any thoughts on why peek is acting differently now that there is an SQL statment in the mix?
Your SQL statement appears after the peek()... you don't show the part of the script tha loads the previous table...
The SQL statement by itself shouldn't change much. If your previous statement is also a new SQL, - check if your fields have the same upper-lower case as you spelled them in the peek(). It looks like your SQL only returns upper case fields...