User Defined Functions
==========================
1. Defining a Function without arguments
Syntax:
Function <function name>()
Statements
End Function
Eg: Adding two numbers
Difining Function
-----------------------
Function Sum()
a=10
b=20
c=a+b
print c
End Function
Calling Function
------------------------
1. Using Call method
eg:
Call Sum()
2. Without Call method
eg:
Sum()
3. using variable
x=Sum()
Example
------------------------
Function sum(x, y)
print x+y
End Function
Call sum(10,20)
Call sum(5,9)
To View Local Functions
--------------------------------------
View -> Toolbox
Types of Arguments
----------------------------
1. ByVal : It refers the value
2. ByRef : It refers the memory location. By default argument type is ByRef.
Example
---------------
Function Sample(Byval a, Byref b,c)
a=100
b=200
c=300
End Function
a=10
b=20
c=30
Call sample(a,b,c)
msgbox a
msgbox b
msgbox c
Note:
----------
You will get output
10
200
300
a is ByVal. So, which value is there that you will get. b and c are ByRef, so it takes values from where you defined in funtion.
Example
----------------------`
Function Sum(a,b,c)
c=a+b
End Function
Call sum(2,3,c)
msgbox c
==========================
1. Defining a Function without arguments
Syntax:
Function <function name>()
Statements
End Function
Eg: Adding two numbers
Difining Function
-----------------------
Function Sum()
a=10
b=20
c=a+b
print c
End Function
Calling Function
------------------------
1. Using Call method
eg:
Call Sum()
2. Without Call method
eg:
Sum()
3. using variable
x=Sum()
Example
------------------------
Function sum(x, y)
print x+y
End Function
Call sum(10,20)
Call sum(5,9)
To View Local Functions
--------------------------------------
View -> Toolbox
Types of Arguments
----------------------------
1. ByVal : It refers the value
2. ByRef : It refers the memory location. By default argument type is ByRef.
Example
---------------
Function Sample(Byval a, Byref b,c)
a=100
b=200
c=300
End Function
a=10
b=20
c=30
Call sample(a,b,c)
msgbox a
msgbox b
msgbox c
Note:
----------
You will get output
10
200
300
a is ByVal. So, which value is there that you will get. b and c are ByRef, so it takes values from where you defined in funtion.
Example
----------------------`
Function Sum(a,b,c)
c=a+b
End Function
Call sum(2,3,c)
msgbox c
No comments:
Post a Comment