1. Function procedures
2. Sub procedures
Function can return the value, where as procedure can't return the value
Syntax of Function:
Function
Dim c
C= Arg1*Arg2
End function
Syntax of procedure:
Sub
Dim c
C = Arg1*Arg2
End sub
Call
Local Procedure: Defining a procedure and reusing it in the same script is called local procedure
Global procedure: Defining a procedure in a library file and reusing it across multiple scripts is called global procedure
Eg:1 Function with single return value
Function calc(a,b)
Dim c
C= a*b
calc = c
End function
Res = calc(7,8)
msgbox res
Note: To return the value from a function we need to assign the return value to the name of a function. When ever we are returning the value, parenthesis () is must.
Eg:2 Function with multiple return values
Function calc(ByVal a,ByVal b,Byref c,ByRef d)
c= a*b
d=a+b
End function
Calc 7,8,x,y
msgbox x
msgbox y
Eg:3 Function & procedure with multiple return values
Function calc(ByVal a,ByVal b,Byref c,ByRef d)
c= a*b
d=a+b
End function
Sub sample()
Msgbox “Hi All”
End Sub
Calc 7,8,x,y
msgbox x
msgbox y
call sample
Note: Save the function or procedure in notepad & save it as .vbs file
No comments:
Post a Comment