Back to Blog

Vugen: Loop Through An Array Of Parameters

I had a situation where I needed to find a specific record within a list. The web page had a list of 300 orders, and I had to find an order with a matching status of “NONE” based on some text displayed. The first thing I had to do was capture all the statuses and put them into an array, and then find a match.

To get the statuses into an array, I used the ORD=ALL argument with the web_reg_save_param function:

// Get all 300 orders displayed on this HTML page
 web_url( http://...get the page... );

To find an order with a status of “NONE”, I needed to access the array of parameter values by referencing their count (i.e. statusA_1, statusA_2, statusA_3, etc.), looping through and comparing the text value of them. Once I find one that matches the status of “NONE” , I break the loop.

for( i=1; i<301; i++)
 sprintf(status, "{statusA_%d}", i );
 lr_output_message(".....Looking for Status as NONE - %d - %s ",
     i, lr_eval_string(status) );
 if(!strcmp( lr_eval_string(status), "NONE"))
 lr_output_message("......Found Status as NONE....");

Once the status of the order is known, I figured I might need the order  number for something, so I created a variable with the parameter name that contains the order
number for the same order we found the status “NONE” for:

sprintf(order_num, "{orderID_%d}", i );
lr_output_message("i: %d OrderID: %s", i, lr_eval_string(order_num) );

Hopefully this helps you get a starting point for a similar situation. Let me know if you come up with alternative ways to do this in the comment section below.

Back to Blog