Hi All
This is regarding ByVal ByRef
Its taken me over a year to try and understand this concept as I feel either I just dont get it or people are not explaining it to me very well.
Am I right in saying that ByVal and ByRef only matters if the called sub or Function changes the values of its own parameter variable. i.e.
So ByVal would take a copy of the Param variable where as ByRef would directly modify the location in memory of Param. So despite Param equaling 5 - if its called ByRef then if the calling Sub changes Param then that is the value that would be used and vice versa for ByVal.
However, let say the code was written as below
Then it doesnt matter if its ByVal or ByRef because this is only used for when the Called Sub or Function changes its own Parameter variable.
But if this is the case then I cant ever see a live example of me ever wanting to use this in a real world example.
Any clarification would be greatly appreciated.
Thanks
This is regarding ByVal ByRef
Its taken me over a year to try and understand this concept as I feel either I just dont get it or people are not explaining it to me very well.
Am I right in saying that ByVal and ByRef only matters if the called sub or Function changes the values of its own parameter variable. i.e.
Code:
Function Test(ByRef Param as Integer)
Param = 5
End Sub
So ByVal would take a copy of the Param variable where as ByRef would directly modify the location in memory of Param. So despite Param equaling 5 - if its called ByRef then if the calling Sub changes Param then that is the value that would be used and vice versa for ByVal.
However, let say the code was written as below
Code:
Function Test(Param as Integer)
'Some code here that doesnt change the value of Param
End Sub
Then it doesnt matter if its ByVal or ByRef because this is only used for when the Called Sub or Function changes its own Parameter variable.
But if this is the case then I cant ever see a live example of me ever wanting to use this in a real world example.
Any clarification would be greatly appreciated.
Thanks