Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
nicolas_martin
Partner - Creator II
Partner - Creator II

Problem with peek()

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?

1 Solution

Accepted Solutions
nagaiank
Specialist III
Specialist III

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.

View solution in original post

6 Replies
Anonymous
Not applicable

Hi,

Table1: 

LOAD * INLINE [ 

Field1 

Aaa 

Bbb 

Ccc 

]; 

 

LET nbVal = FieldValueCount('Field1'); 

 

Table2: 

LOAD * INLINE [ 

Field2 

]; 

 

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 

nicolas_martin
Partner - Creator II
Partner - Creator II
Author

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?

Anonymous
Not applicable

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.

nagaiank
Specialist III
Specialist III

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.

nicolas_martin
Partner - Creator II
Partner - Creator II
Author

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".

Anonymous
Not applicable

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.