I am trying to learn the differences between ByVal and ByRef. Below is a summary of what I have currently learned (or think I have):
- Change original variable passed as argument: ByVal = can not change (passes a copy of the value only), ByRef = can change (passes the original reference) (hence their names)
- Passing Arrays: ByVal = Can't do (error), ByRef = Always use for passing arrays as arguments
- Passing objects: ByVal = Can not use on objects? ByRef = Always?
- Speed: ByVal = slightly slower, ByRef = slightly faster
- Argument type: ByRef = must be same variable type passed? ByVal = ?
- If not declared: ByVal = not default, ByRef = Default
My questions:
- If there is anything I have incorrect in the above, could someone please let me know?
- Is there anything important missing from my summary that I should be learning?
- I fail to see any benefits of using ByVal over ByRef (unless you are paranoid about the possibility of altering the original variable). Or am I missing something big here? Please enlighten me if so.
Thanks for any help/corrections.![]()
Bookmarks