Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I've a inline table
F1 | F2 |
1 | A |
2 | B |
3 | C |
I would like to loop both columns and assign a variable to them accordingly to be used. example:
For x,y in FieldValueList(F1,F2)
set vX ="x";
set vY ="y";
Trace $(vX) and $(vY) ;
next
The result i get should be:
1 and A
2 and B
3 and C
but the above for loop syntax is wrong. what is the right syntax?
thanks in advance
Yes, the syntax is wrong and it wouldn't work with multiple fields at the same time - else only for a single field and then the next one and/or nesting multiple loops.
Beside this the above won't work within many scenarios because the field-values are on the field-level independent to each other. To get multiple fields synchronized you need to loop through a table, maybe like this:
for i = 0 to noofrows('MyTable') - 1
let v1 = peek('Field1, $(i), 'MyTable');
let v2 = peek('Field2, $(i), 'MyTable');
trace $(v1) + $(v2);
next
Yes, the syntax is wrong and it wouldn't work with multiple fields at the same time - else only for a single field and then the next one and/or nesting multiple loops.
Beside this the above won't work within many scenarios because the field-values are on the field-level independent to each other. To get multiple fields synchronized you need to loop through a table, maybe like this:
for i = 0 to noofrows('MyTable') - 1
let v1 = peek('Field1, $(i), 'MyTable');
let v2 = peek('Field2, $(i), 'MyTable');
trace $(v1) + $(v2);
next
Thank you! @marcus_sommer it is exactly what I needed.
interesting that this: for i = 0 to noofrows('MyTable') - 1 indicates that the index of the table starts at 0
but if I use this instead the index starts at 1 :
For Each i in FieldValueList('F1')
LET idx_i = FieldIndex('F1','$(i)');
The same index-range and also the same notation-requirements for table/field-names everywhere would be too easy 😉