Examples
实例
Sub procedure
The sub procedure does not return a value.
sub程序不会返回值
Function procedure
The function procedure is used if you want to return a value.
当你想返回值可以使用函数程序
VBScript Procedures
VBScript程序
We have two kinds of procedures: The Sub procedure and the Function procedure.
我们来看看这两种程序:Sub程序和Function(函数)程序
A Sub procedure:
Sub程序:
is a series of statements, enclosed by the Sub and End Sub statements
位于Sub和End Sub之间的一系列声明
can perform actions, but does not return a value
可以执行动作,但不能返回值
can take arguments that are passed to it by a calling procedure
通过调用程序还能获取带来的参数
without arguments, must include an empty set of parentheses ()
如果没有参数,必须含有空括号()
Sub mysub()
some statements
End Sub
or
Sub mysub(argument1,argument2)
some statements End Sub
A Function procedure:
函数程序:
is a series of statements, enclosed by the Function and End Function statements
位于Function和End Function之间的一系列声明
can perform actions and can return a value
可以执行行为同时还能返回值
can take arguments that are passed to it by a calling procedure
通过调用程序还能获取带来的参数
without arguments, must include an empty set of parentheses ()
如果没有参数,必须含有空括号()
returns a value by assigning a value to its name
通过给它的名称赋值来返回执行程序后的返回值
Function myfunction()
some statements
myfunction=some value
End Function
or
Function myfunction(argument1,argument2)
some statements
myfunction=some value
End Function
Call a Sub or Function Procedure
调用Sub或是Function程序
When you call a Function in your code, you do like this:
当你在代码中要调用Function的时候你可以这样:
name = findname()
Here you call a Function called "findname", the Function returns a value that will be stored in the variable "name".
这个时候你已经调用了一个名为"findname"的Function(函数)了。函数会把产生的值返回到并存储到变量"name"中
Or, you can do like this:
或者,你可以这样做:
msgbox "Your name is " & findname()
Here you also call a Function called "findname", the Function returns a value that will be displayed in the message box.
这样你也是调用了名为"findname"的函数,它会将返回的结果连同前面的字符串一起显示在信息框中。
When you call a Sub procedure you can use the Call statement, like this:
当你要调用Sub程序的时候可以使用Call声明,像这样:
Call MyProc(argument)
Or, you can omit the Call statement, like this:
或者你可以将Call忽略掉这样声明:
MyProc argument

