Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Looping through a crosstable

Hi All.

Is there something special about looping though a crosstab? I am getting very odd results with the following approach.

FOR  vRowCounter = 1 TO NoOfRows('MasterScoreXTAB')

     LET vField1  = FieldValue('Field A',vRowCounter);

     LET vField2  = FieldValue('Field B',vRowCounter);

     LET vField3  = FieldValue('Field C',vRowCounter);

     Trace =====> $(vField1) ++ $(vField2) ++$(vField3)

NEXT

With this construct I am expecting to see each fields of the Crosstab row side-by-side. But $(vField2) is showing values from a different row in the crosstab, as if vRowCounter was being incremented several times within a single loop cycle.

Any hint?

4 Replies
Colin-Albert

Not applicable
Author

Thanks Collin.

My table was indeed created using the Crosstable Load function, but I am not sure what the article your refer to means for my issue. I have read through all the subsequent posts, and I didn't find a mention about looping through a crosstable.

Gysbert_Wassenaar

The fieldvalue function gets data from an internal symbol table, not the table you created with the crosstable function. The record numbers of the symbol table are completely unrelated to the record numbers of the table the crosstable function created.


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks Gysbert.

And indeed, using peek works, like so:

FOR  vRowCounter = 1 TO NoOfRows('MasterScoreXTAB')

     LET vField1  = Peek('Field A',vRowCounter);

     LET vField2  = Peek('Field B',vRowCounter);

     LET vField3  = Peek('Field C',vRowCounter);

     Trace =====> $(vField1) ++ $(vField2) ++$(vField3)

NEXT