i want to ask..
if i'm going to make a sub module..what is the best method to passing parameter...byval or byref?
thanks,
erick
Printable View
i want to ask..
if i'm going to make a sub module..what is the best method to passing parameter...byval or byref?
thanks,
erick
i prefer byval so the passed value would not be changed by th caller and will not cause strange changes to your variables, but its my own opinion.
Hi,
It depends on your parameter usuage within your function defintion. Usually by referrence is used when you need to change the parameter within your function defintion.
Pass by value shall be used when you want to read parameter data information and use that info within your function. It has a overload that it calls copy constructor of your passed object. If you are sure that you dont want to modify the parameter object inside your function you can make passing parameter as immuttable. (const Object &Obvar .).
thanks for the information
it's not always better byval or byref..it depends on the situation..
thanks
Indeed, basically if you don't need to pass them ByRef, then pass them ByVal.
Unlike one would think, ByVal is actually faster than ByRef because it does not need to pass back the data in the parameter(s) you passed. In VB, evertything is passed ByRef instead of ByVal, unless otherwise specified. This is done because some datatypes cannot be passed byval, such as Objects.
Anyway, it's a good practice to always explicitly define whether or not a value is passed ByRef or ByVal. Not only will it be more efficient, it will also be easier for others to understand your code, since they can directly see wheter or not you are going to change the data that has been passed to the procedure.