|
lr_paramarr_random()函数作用是:随机取得关联回来的参数数组的值。
附,何为参数数组:在使用web_reg_save_param函数时,当设置Ord=All时,关联返回的就是一个参数数组,在LR9.X的版本提供支持。参数数组中参数的名称变成了param_x (多了_x,x表示参数数组中的索引)
在8.X的版本中不提供该函数,所以要随机取得值需要使用到rand()函数和sprintf组合来构造出一个类似param_1的字符串作为参数的名称,例子如下:
以LR自带的webtours为例,启动后可练习如下代码:
web_reg_save_param("flightnumber",
"LB/DIG=##/##/####>",
"RB/ALNUMIC=<td align=^enter>",
"Ord=ALL",
LAST);
web_submit_data("reservations.pl",
"Action=http://localhost:1080/webtours/reservations.pl",
"Method=POST",
ITEMDATA,
"Name=advanceDiscount", "Value=0", ENDITEM,
"Name=depart", "Value=Denver", ENDITEM,
"Name=departDate", "Value=11/29/2009", ENDITEM,
"Name=arrive", "Value=London", ENDITEM,
"Name=returnDate", "Value=11/30/2009", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=seatPref", "Value=None", ENDITEM,
"Name=seatType", "Value=Coach", ENDITEM,
"Name=.cgifields", "Value=roundtrip", ENDITEM,
"Name=.cgifields", "Value=seatType", ENDITEM,
"Name=.cgifields", "Value=seatPref", ENDITEM,
"Name=findFlights.x", "Value=44", ENDITEM,
"Name=findFlights.y", "Value=15", ENDITEM,
LAST);
b = lr_paramarr_len("flightnumber");
for (w=0; w<b; w++) {
lr_output_message(lr_paramarr_idx("flightnumber", w+1));
}
lr_output_message(lr_paramarr_random("flightnumber"));
// lr 8.x 使用,无非就是用sprintf拼出flightnumber_x这样的参数名字.
for (w=0; w<atoi(lr_eval_string("{flightnumber_count}")); w++) {
sprintf(str, "{flightnumber_%d}", w+1);
lr_output_message(lr_eval_string(str));
} |
|