Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I would like to loop on every value of a field, with the "peek" function.
The following code works:
Table1:
LOAD * INLINE [
Field1
Aaa
Bbb
Ccc
];
LET nbVal = FieldValueCount('Field1');
FOR _i = 0 TO nbVal - 1
LET _val = peek('Field1', _i);
LET _res = MsgBox('$(_val)');
NEXT _i
This will pop up "Aaa", "Bbb" and "Ccc".
But if I load another table between the table and the loop, it doesn't work anymore:
Table1:
LOAD * INLINE [
Field1
Aaa
Bbb
Ccc
];
LET nbVal = FieldValueCount('Field1');
Table2:
LOAD * INLINE [
Field2
1
2
3
];
FOR _i = 0 TO nbVal - 1
LET _val = peek('Field1', _i);
LET _res = MsgBox('$(_val)');
NEXT _i
I don't understand why loading another table prevents the "peek()" to succeed.
If I'm adding the table:
LET _val = peek('Field1', _i, 'Table1');
it works.
Does that means the function "peek" with 2 parameters is not reliable?
The Reference manual states that if the Tablename argument is not specified, the current table is assumed. If you want to refer any table other than the current table, you need to specify the table.
Hi,
Table1:
LOAD * INLINE [
Field1
Aaa
Bbb
Ccc
];
LET nbVal = FieldValueCount('Field1');
Table2:
LOAD * INLINE [
Field2
1
2
3
];
FOR _i = 0 TO nbVal - 1
LET _val = peek('Field1', _i,'TableName'); //Give table name here when another table in between
LET _res = MsgBox('$(_val)');
NEXT _i
Indeed, but I would like to understand why.
The "Field1" field is only in the table "Table1". Why do I have to make the precision?
Hi,
The Peek() function can be used in a load to retrieve data from the same table or from another table. in these case the table name is mandatory, as table which we are refering is not immediate table in the script.
The Reference manual states that if the Tablename argument is not specified, the current table is assumed. If you want to refer any table other than the current table, you need to specify the table.
Thank you.
I misunderstood the meaning of the phrase in the Reference Manual.
I thought it was "it takes the last table having this field".
Hi Nicolas,
The Peek() function can be used in a load to retrieve data from the same table or from another table. in these case the table name is mandatory, as table which we are refering is not immediate(Current) table in the script.