first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

ByVal and ByRef; Functions and Classes

When a variable is passed to a function, by default (since VB 4.0) it is passed by reference. If the variable is local to the procedure calling the function, an error will be generated if the function does not use the ByVal keyword in the argument list. However, module-level or Public variables can be passed.

The opinion here is that the explicit use of ByRef against variables that are not object variables ultimately means that there will be several Public or module variables having their values changed in many different procedures. Logically managing these variables seems more difficult than using the Classes available in any OLE Automation object hosting VBA 5.0 and above (e.g. VB 4.0 and above or Access 95 and above).

Before the advent of Visual Basic objects (in VB 3.x) ByVal was the default method of passing a variable to a function. To make the use of object variables "easier," I suppose Microsoft was led to switch over to ByRef being default in the object-oriented world of Visual Basic.

mod date: 1999-01-12T05:34:33.000Z