调用函数后取不到值?
大家帮我看看为什么红色部分取不到值?static in_price,in_total;
static tickets,price,total;
static function retrieve(in dollar_in, in dollar_out)
{
auto dollar_array[];
split(dollar_in, dollar_array,"$");
dollar_out=dollar_array;
#pause(dollar_out);
return (dollar_out);
}
static function compare(in com_price,in com_tickets)
{
auto t;
# pause(com_tickets);
# pause(com_price);
t=com_tickets*com_price;
if(t==in_total)
tl_step("compare results:",0,"successful");
else
tl_step("compare results:",1,"failed");
}
set_window ("Flight Reservation", 5);
menu_select_item ("File;Open Order...");
set_window("Flight Reservation");
set_window("Open Order");
button_set("Order No.",ON);
edit_set("Edit_1","55");
button_press("OK");
set_window("Flight Reservation");
edit_get_text("Tickets:",tickets);
edit_get_text("Price:",price);
edit_get_text("Total:",total);
retrieve(price,in_price);
pause(in_price); #不知道为什么该处取不到 in_price 和 in_total 的值?
retrieve(total,in_total);
pause(in_total);
compare(in_price,tickets); in_price是你传进去的参数,参数没有赋值,当然取不到值了,b=retrieve(total,in_total);pause(b); 这样就能得到你要的值了,是调用函数的返回值. 实际上你写的那个函数,只需要一个参数就可以了.如下:
static function retrieve(in dollar_in)
{
auto dollar_out;
auto dollar_array[];
a=split(dollar_in, dollar_array,"$");
dollar_out=dollar_array;
#pause(dollar_out);
return (dollar_out);
} 原帖由 piao_604 于 2006-10-31 17:14 发表
in_price是你传进去的参数,参数没有赋值,当然取不到值了,b=retrieve(total,in_total);pause(b); 这样就能得到你要的值了,是调用函数的返回值. 实际上你写的那个函数,只需要一个参数就可以了.如下:
static func ...
你的这句话提醒了我, 我知道怎么修改了. thank you
static function retrieve(in dollar_in, out dollar_out)
{
........
}
还是要用俩个参数
如果按照你说的方法只用一个参数的话, 在 retrieve()里没有错, 但是当 funciton compare() 调用retrieve() 的返回值时就会发生调用错误的返回值, 导致测试的结果不正确.
这个我运行了是可以的
static in_price,in_total;static tickets,price,total;
static function retrieve(in dollar_in)
{
auto dollar_array[];
auto dollar_out;
split(dollar_in, dollar_array,"$");
dollar_out=dollar_array;
#pause(dollar_out);
return (dollar_out);
}
static function compare(in com_price,in com_tickets)
{
auto t;
# pause(com_tickets);
# pause(com_price);
t=com_tickets*com_price;
if(t==in_total)
tl_step("compare results:",0,"successful");
else
tl_step("compare results:",1,"failed");
}
set_window ("Flight Reservation", 5);
menu_select_item ("File;Open Order...");
#set_window("Flight Reservation");
set_window("Open Order");
button_set("Order No.",ON);
edit_set("Edit_1","5");
button_press("OK");
set_window("Flight Reservation");
edit_get_text("Tickets:",tickets);
edit_get_text("Price:",price);
edit_get_text("Total:",total);
in_price = retrieve(price);
pause(in_price);
in_total = retrieve(total);
pause(in_total);
compare(in_price,tickets);
这个我运行了是可以的
static in_price,in_total;static tickets,price,total;
static function retrieve(in dollar_in)
{
auto dollar_array[];
auto dollar_out;
split(dollar_in, dollar_array,"$");
dollar_out=dollar_array;
#pause(dollar_out);
return (dollar_out);
}
static function compare(in com_price,in com_tickets)
{
auto t;
# pause(com_tickets);
# pause(com_price);
t=com_tickets*com_price;
if(t==in_total)
tl_step("compare results:",0,"successful");
else
tl_step("compare results:",1,"failed");
}
set_window ("Flight Reservation", 5);
menu_select_item ("File;Open Order...");
#set_window("Flight Reservation");
set_window("Open Order");
button_set("Order No.",ON);
edit_set("Edit_1","5");
button_press("OK");
set_window("Flight Reservation");
edit_get_text("Tickets:",tickets);
edit_get_text("Price:",price);
edit_get_text("Total:",total);
in_price = retrieve(price);
pause(in_price);
in_total = retrieve(total);
pause(in_total);
compare(in_price,tickets); 学习了一把.
页:
[1]