Pass ByRef and Pass ByVal --> DEMO
"
"
' 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
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
' 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
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