ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: VBScript :: VBScript ³ÌÐò

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

VBScript
VBScript ½éÉÜ
ÈçºÎʹÓà VBScrip..
VBScript ·ÅÖÃ
VBScript ±äÁ¿
VBScript ³ÌÐò
VBScript Ìõ¼þÓï¾..
VBScript Ñ­»·ÉùÃ..
VBScript ÕªÒª
VBScript ʵÀý
VBScript º¯Êý
VBScript ¹Ø¼ü×Ö

VBScript ³ÌÐò


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-28 ä¯ÀÀ:2101 :: ::

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

ÆÀÂÛ (1) 1 All