Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:vbsprocedures [2015/09/14]
127.0.0.1 external edit
developer:vbsprocedures [2016/01/05] (current)
sandy
Line 3: Line 3:
 > **Summary:​** //Overview of VBScript procedures.//​ > **Summary:​** //Overview of VBScript procedures.//​
  
-=====See ​Also===== +Also see [[developer:​vbsfundamentals|VBScript Fundamentals]].
-[[developer:​vbsfundamentals|VBScript Fundamentals]]+
  
 =====Overview===== =====Overview=====
  
-In VBScript, there are two kinds of proceduresthe **Sub** procedure and the **Function** procedure.+In VBScript, there are two kinds of proceduresthe **Sub** procedure and the **Function** procedure.
  
-=====Sub ​Procedures=====+=====Sub ​procedures=====
  
 A **Sub** procedure is a series of VBScript statements (enclosed by **Sub** and **End Sub** statements) that perform actions but don't return a value. A **Sub** procedure can take arguments (constants, variables, or expressions that are passed by a calling procedure). If a **Sub** procedure has no arguments, its **Sub** statement should include an empty set of parentheses (). A **Sub** procedure is a series of VBScript statements (enclosed by **Sub** and **End Sub** statements) that perform actions but don't return a value. A **Sub** procedure can take arguments (constants, variables, or expressions that are passed by a calling procedure). If a **Sub** procedure has no arguments, its **Sub** statement should include an empty set of parentheses ().
Line 23: Line 22:
 </​code>​ </​code>​
  
-===== Function ​Procedures=====+===== Function ​procedures=====
  
 A **Function** procedure is a series of VBScript statements enclosed by the **Function** and **End Function** statements. A **Function** procedure is similar to a **Sub** procedure, but can also return a value. A **Function** procedure can take arguments (constants, variables, or expressions that are passed to it by a calling procedure). If a **Function** procedure has no arguments, its **Function** statement should include an empty set of parentheses. A **Function** returns a value by assigning a value to its name in one or more statements of the procedure. The return type of a **Function** is always a **Variant**. A **Function** procedure is a series of VBScript statements enclosed by the **Function** and **End Function** statements. A **Function** procedure is similar to a **Sub** procedure, but can also return a value. A **Function** procedure can take arguments (constants, variables, or expressions that are passed to it by a calling procedure). If a **Function** procedure has no arguments, its **Function** statement should include an empty set of parentheses. A **Function** returns a value by assigning a value to its name in one or more statements of the procedure. The return type of a **Function** is always a **Variant**.
Line 40: Line 39:
 </​code>​ </​code>​
  
-=====Getting ​Data into and out of Procedures=====+=====Getting ​data into and out of procedures=====
  
 Each piece of data is passed into your procedures using an argument. Arguments serve as placeholders for the data you want to pass into your procedure. You can name your arguments any valid variable name. When you create a procedure using either the **Sub** statement or the **Function** statement, parentheses must be included after the name of the procedure. Any arguments are placed inside these parentheses,​ separated by commas. For example, in the following example, //​fDegrees//​ is a placeholder for the value being passed into the //Celsius// function for conversion. Each piece of data is passed into your procedures using an argument. Arguments serve as placeholders for the data you want to pass into your procedure. You can name your arguments any valid variable name. When you create a procedure using either the **Sub** statement or the **Function** statement, parentheses must be included after the name of the procedure. Any arguments are placed inside these parentheses,​ separated by commas. For example, in the following example, //​fDegrees//​ is a placeholder for the value being passed into the //Celsius// function for conversion.
Line 52: Line 51:
 To get data out of a procedure, you must use a **Function**. Remember, a **Function** procedure can return a value; a **Sub** procedure cannot. To get data out of a procedure, you must use a **Function**. Remember, a **Function** procedure can return a value; a **Sub** procedure cannot.
  
-=====Using ​Sub and Function Procedures ​in Code=====+=====Using ​sub and function procedures ​in code=====
  
 A **Function** in your code must always be used on the right side of a variable assignment or in an expression. For example: A **Function** in your code must always be used on the right side of a variable assignment or in an expression. For example:
developer/vbsprocedures.txt · Last modified: 2016/01/05 by sandy