Argument types in Functions
"
Arguments can be passed as
"
Argument types in Functions
Arguments can be passed as
· Pass ByValue
· Pass ByReference
Represented as
ByRef
ByVal
Description about ByVal:
Indicates that the argument is passed by value.
Description about ByRef :
Indicates that the argument is passed by reference.
Note: By default all arguments are 'ByRef'.
Description about ByVal:
Indicates that the argument is passed by value.
Description about ByRef :
Indicates that the argument is passed by reference.
Note: By default all arguments are 'ByRef'.
o
ByRef explains that the
value which is assigned to the variable within the function is permanent and we
can use that value outside of that function too
o
It references the
function and corresponding value assigned within the function
o
ByVal explains that the
value which is assigned to the variable within the function is temporary and we
can use that value only within that function.
o
It references the value assigned outside of the function
Examples:
' Arguments passing to functions
'
Pass ByRef
' Pass ByVal;
'‘*********************************************************************************************
' Function name : Demo_PassingArgs1
' Variables : num1 , num2
--.> num1 and num2 are declared as ByRef (BY DEFAULT)
' Passed
arguments a,b : a=10,
b=20
' Returning values : a=100, b=200 (
because a=num1, b=num2 ; both these values are passed as ByRef
'‘*********************************************************************************************
a=10
b=20
msgbox Demo_PassingArgs1(a,b)
msgbox a
msgbox b
Function Demo_PassingArgs1(num1,num2)
num1=100
num2=200
Demo_PassingArgs1=num1+num2
End Function
'‘*********************************************************************************************
' Function name : Demo_PassingArgs2
' Variables : num1 , num2
--.> num1 and num2 are declared as ByRef
' Passed
arguements a,b : a=10, b=20
' Returing values : a=100, b=200 ( because a=num1, b=num2 ; both these
values are passed as ByRef
'‘*********************************************************************************************
a=10
b=20
msgbox Demo_PassingArgs2(a,b)
msgbox a
msgbox b
Function Demo_PassingArgs2(ByRef
num1,ByRef num2)
num1=100
num2=200
Demo_PassingArgs2=num1+num2
End Function
'‘*********************************************************************************************'
Function name : Demo_PassingArgs3
' Variables : num1 , num2
--.> num1 and num2 are declared as ByVal (declared in function)
' Passed
arguements a,b : a=10, b=20
' Returing values : a=10, b=20 ( because a=num1, b=num2 ; both
these values are passed as ByVal
'‘*********************************************************************************************
a=10
b=20
msgbox Demo_PassingArgs3(a,b)
msgbox a
msgbox b
Function Demo_PassingArgs3(ByVal
num1,ByVal num2)
num1=100
num2=200
Demo_PassingArgs3=num1+num2
End Function
'‘*********************************************************************************************
' Function name : Demo_PassingArgs4
' Variables : num1 , num2
--.> num1 is declared as ByRef
and num2 is declared as ByVal
' Passed
arguements a,b : a=10, b=20
' Returing values : a=100,
b=20( because a=num1 (here num1 is ByRef) , b=num2 (here num2 is ByVal)
'‘*********************************************************************************************
a=10
b=20
msgbox Demo_PassingArgs4(a,b)
msgbox a
msgbox b
Function Demo_PassingArgs4(ByRef
num1,ByVal num2)
num1=100
num2=200
Demo_PassingArgs4=num1+num2
End Function
Argument types in Functions
Arguments can be passed as
· Pass ByValue
· Pass ByReference
Represented as
ByRef
ByVal
Description about ByVal:
Indicates that the argument is passed by value.
Description about ByRef :
Indicates that the argument is passed by reference.
Note: By default all arguments are 'ByRef'.
Description about ByVal:
Indicates that the argument is passed by value.
Description about ByRef :
Indicates that the argument is passed by reference.
Note: By default all arguments are 'ByRef'.
o
ByRef explains that the
value which is assigned to the variable within the function is permanent and we
can use that value outside of that function too
o
It references the
function and corresponding value assigned within the function
o
ByVal explains that the
value which is assigned to the variable within the function is temporary and we
can use that value only within that function.
o
It references the value assigned outside of the function
Examples:
' Arguments passing to functions
'
Pass ByRef
' Pass ByVal;
'‘*********************************************************************************************
' Function name : Demo_PassingArgs1
' Variables : num1 , num2
--.> num1 and num2 are declared as ByRef (BY DEFAULT)
' Passed
arguments a,b : a=10,
b=20
' Returning values : a=100, b=200 (
because a=num1, b=num2 ; both these values are passed as ByRef
'‘*********************************************************************************************
a=10
b=20
msgbox Demo_PassingArgs1(a,b)
msgbox a
msgbox b
Function Demo_PassingArgs1(num1,num2)
num1=100
num2=200
Demo_PassingArgs1=num1+num2
End Function
'‘*********************************************************************************************
' Function name : Demo_PassingArgs2
' Variables : num1 , num2
--.> num1 and num2 are declared as ByRef
' Passed
arguements a,b : a=10, b=20
' Returing values : a=100, b=200 ( because a=num1, b=num2 ; both these
values are passed as ByRef
'‘*********************************************************************************************
a=10
b=20
msgbox Demo_PassingArgs2(a,b)
msgbox a
msgbox b
Function Demo_PassingArgs2(ByRef
num1,ByRef num2)
num1=100
num2=200
Demo_PassingArgs2=num1+num2
End Function
'‘*********************************************************************************************'
Function name : Demo_PassingArgs3
' Variables : num1 , num2
--.> num1 and num2 are declared as ByVal (declared in function)
' Passed
arguements a,b : a=10, b=20
' Returing values : a=10, b=20 ( because a=num1, b=num2 ; both
these values are passed as ByVal
'‘*********************************************************************************************
a=10
b=20
msgbox Demo_PassingArgs3(a,b)
msgbox a
msgbox b
Function Demo_PassingArgs3(ByVal
num1,ByVal num2)
num1=100
num2=200
Demo_PassingArgs3=num1+num2
End Function
'‘*********************************************************************************************
' Function name : Demo_PassingArgs4
' Variables : num1 , num2
--.> num1 is declared as ByRef
and num2 is declared as ByVal
' Passed
arguements a,b : a=10, b=20
' Returing values : a=100,
b=20( because a=num1 (here num1 is ByRef) , b=num2 (here num2 is ByVal)
'‘*********************************************************************************************
a=10
b=20
msgbox Demo_PassingArgs4(a,b)
msgbox a
msgbox b
Function Demo_PassingArgs4(ByRef
num1,ByVal num2)
num1=100
num2=200
Demo_PassingArgs4=num1+num2
End Function
0 comments:
Post a Comment