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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top