View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Keith Willshaw Keith Willshaw is offline
external usenet poster
 
Posts: 170
Default Is ByVal always better if ByRef isn't necessary


"Jeff" wrote in message
...
If a variable is not being modified in the passed to sub
or function, is there a reason to specify ByVal rather
than allowing the default ByRef.

And same question if a value is being passed.

In these cases I do not perceive any practical difference
between ByVal or ByRef, but somehow I suspect there is!

TIA for clarifaction,
Jeff


To amplify what Rob has already said I'll try and
explain the fundamental difference in ByRef and ByVal

When you pass an argument ByVal what the system does

1) go to the location in memory that the variable was stored in
2) get the value.
3) Copy this value to another location
4) Pass the address of the new memory location to the
routine that is being called

When you pass an argument ByRef all that happens
is the address of that memory is passed to the calling routine

Keith