w3pop.com :: ÍøÂçѧԺ :: VBScript :: VBScript ³ÌÐò
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.
µ±ÄãÏë·µ»ØÖµ¿ÉÒÔʹÓú¯Êý³ÌÐò
We have two kinds of procedures: The Sub procedure and the Function procedure.
ÎÒÃÇÀ´¿´¿´ÕâÁ½ÖÖ³ÌÐò:Sub³ÌÐòºÍFunction(º¯Êý)³ÌÐò
A Sub procedure:
Sub³ÌÐò£º
Sub mysub() or Sub mysub(argument1,argument2) |
A Function procedure:
º¯Êý³ÌÐò£º
Function myfunction() or Function myfunction(argument1,argument2) |
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 |