标签:style blog color io 使用 for sp div on
function f_add(num_in) num_in = num_in + 1 f_add = num_in end function
用函数名来返回参数
sub s_add(num_in) num_in = num_in + 1 end sub
子例程没有返回值
函数和子例程调用时可以有两种方式:在括号中指定参数,或使用不带括号的格式。
使用带括号的方式指定参数时,参数是按值传递的,函数或子例程中对参数的修改不会反映到参数中。而用不带括号的格式时,则函数或子例程中对参数值的改动都是实际发生的。
以下代码示范了这两种格式的差别:
num_out = 0 wscript.echo "num before sub:", num_out ‘用不带括号的格式调用子例程 s_add num_out wscript.echo "num after sub:", num_out wscript.echo "" num_out = 0 wscript.echo "num before sub():", num_out ‘用带括号的格式调用子例程 s_add(num_out) wscript.echo "num after sub():", num_out wscript.echo "" num_out = 0 wscript.echo "num before function:", num_out ‘用不带括号的格式调用函数 f_add num_out wscript.echo "num after function:", num_out wscript.echo "" num_out = 0 wscript.echo "num before function():", num_out ‘用带括号的格式调用函数 f_add(num_out) wscript.echo "num after function():", num_out wscript.echo "" sub s_add(num_in) wscript.echo "num in sub", num_in num_in = num_in + 1 wscript.echo "num in sub", num_in end sub function f_add(num_in) wscript.echo "num in function", num_in num_in = num_in + 1 wscript.echo "num in function", num_in f_add = num_in end function
输出结果如下
num before sub: 0
num in sub 0
num in sub 1
num after sub: 1
num before sub(): 0
num in sub 0
num in sub 1
num after sub(): 0
num before function: 0
num in function 0
num in function 1
num after function: 1
num before function(): 0
num in function 0
num in function 1
num after function(): 0
标签:style blog color io 使用 for sp div on
原文地址:http://www.cnblogs.com/DigiK0ne/p/4015145.html