In VBScript, a procedure or a function is a set of blocks of code that can perform a particular function, and when we define our own processes or functions, we can call them over and over in the script, and the custom procedure or function can be placed in an external folder and invoked using the #include instruction.
In VBScript, a procedure or a function is a set of blocks of code that can perform a particular function, and when we define our own processes or functions, we can call them over and over in the script, and the custom procedure or function can be placed in an external folder and invoked using the #include instruction.
First, the definition:
To define a procedure format:
Sub Procedure Name (variable 1, variable 2, variable N)
For the procedure body, the statements to be executed when the procedure is invoked
End Sub
A Sub procedure is a set of VBScript statements that are contained between a sub and an End Sub statement, performing an action but not returning a value. Sub procedures can use parameters.
Cases:
Sub MySub (a,b) ' defines a sub subroutine with two parameters
Sum=a*b
End Sub
To define a function format:
Function name (parameter 1, parameter 2, parameter n)
Handling content
function name = Process Result
End Function
A Function procedure is a set of VBScript statements that are contained between a function and an End Function statement. A Function procedure is similar to a Sub procedure, but a Function procedure can return a value. A Function procedure returns a value that is assigned to a function name in the statement of a procedure by its name.
For example:
function My_func (a,b)
Dim sum
Sum=a*b
My_func=sum ' Assign value to function name
End Function
Second, call:
The procedure is invoked in a complete way:
Call My_sub (A,B) ' invokes the Sub subroutine using the calls statement.
It is generally simplified to:
My_sub A,b ' calls sub subroutines without using the call statement, which is the most common method.
How the function is invoked:
Sum=my_func (a,b) ' directly refers to the function name for invocation.