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

for...next cycle problem

Hello, everybody.

I have a table [URLS] with a field [URL], which contains the web address.

I want to make a script, which would proceed through this table and load a certain data, for example, age information from web addresses in each field.

I made script similar to this:


set i = 0;

for i = 0 to 1000

let v_url = PEEK('URL',i,'URLS');

[Data]:

LOAD [Age:] as [Age]
FROM
$(v_url)
(html, unicode, embedded labels, table is @4);

next i

Script works only for the first iteration. After that it for some reason does not recreate v_url variable, it is empty and script fails.

What am I doing wrong?

Thanks in advance!

1 Solution

Accepted Solutions
Not applicable
Author

Hi

I've had problems using peek in situations like this. Can't really remember why but I've used fieldvalue instead successfully.
Something like this:
let noOfRows = noOfRows('URLS');
for i=1 to $(noOfRows)
let v_url = fieldvalue('URL', $(i));
LOAD [Age:] as [Age]
FROM
$(v_url)
(html, unicode, embedded labels, table is @4);
next

Note that fieldvalue returns the value from the field itself, not the value on a specific row within the table.
If you have duplicate values in the URL field you won't get the expected result.
I've solved this by adding a rownumber to the URL field to create unique values and then remove the rownumber when reading from the url.

/Fredrik

View solution in original post

8 Replies
Miguel_Angel_Baeyens

Hello,

Try

LET v_url = PEEK('URL, $(i), 'URLS')


Not applicable
Author

Same result, unfortunately.

Miguel_Angel_Baeyens

First, sorry for my syntax errors in my previous post. Have you tried with

SET v_url = PEEK('URL', $(i), 'URLS');
instead of LET?

Not applicable
Author

To variable v_url in this case is assigned the string ' PEEK('URL', $(i), 'URLS')' itself, instead of the value from URL field.

Miguel_Angel_Baeyens

Indeed. That's what you assign, but then it will be evaluated via macro expansion with $(v_url). LET evaluates expression before being assigned. As far as I understand, you want to look for the name of the record. So thus should work.

Not applicable
Author

Well, it did not evaluate. I received the error message, which notified that table PEEK can' t be opened (instead of web address there was PEEK('URL', $(i), 'URLS') string in FROM part of LOAD statement).

Not applicable
Author

Hi

I've had problems using peek in situations like this. Can't really remember why but I've used fieldvalue instead successfully.
Something like this:
let noOfRows = noOfRows('URLS');
for i=1 to $(noOfRows)
let v_url = fieldvalue('URL', $(i));
LOAD [Age:] as [Age]
FROM
$(v_url)
(html, unicode, embedded labels, table is @4);
next

Note that fieldvalue returns the value from the field itself, not the value on a specific row within the table.
If you have duplicate values in the URL field you won't get the expected result.
I've solved this by adding a rownumber to the URL field to create unique values and then remove the rownumber when reading from the url.

/Fredrik

Not applicable
Author

This worked, thanks!

Still, it was a strange problem.