ByRef v ByVal

J

Jennifer Murphy

It is my understanding that I should use the ByVal keyword if I am
planning to modify the parameter. Is that correct?

Example:

Public Sub Write2File(byval FileID As String, Data As String)

FileID = FileID & ".txt"

....
 
J

joeu2004

Jennifer Murphy said:
It is my understanding that I should use the ByVal
keyword if I am planning to modify the parameter.
Is that correct?

It depends on your objectives.

Yes, use ByVal if you do not want the caller to see the change.

No, use ByRef (default) if you want the caller to see the change.

The latter is not unusual.
 
Top