By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,386 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,386 IT Pros & Developers. It's quick & easy.

What does ByVal mean?

P: n/a
What does "ByVal" mean? I couldn't find it in the Access help messages.
Here is the first line of a function:
Public Function GetAge(ByVal pvarBirthdate As Variant, ByVal pvarAgeCalcDate As
Variant) As Long
Why is ByVal needed? I've written other functions that don't have it, that is,
they would look like:
Public Function GetAge(pvarBirthdate As Variant, pvarAgeCalcDate As Variant) As
Long
Thanks in advance. Pete
Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
pt*****@aol.com (Ptbrady) wrote in
news:20***************************@mb-m14.aol.com:
What does "ByVal" mean? I couldn't find it in the Access help
messages. Here is the first line of a function:
Public Function GetAge(ByVal pvarBirthdate As Variant, ByVal
pvarAgeCalcDate As Variant) As Long
Why is ByVal needed? I've written other functions that don't
have it, that is, they would look like:
Public Function GetAge(pvarBirthdate As Variant,
pvarAgeCalcDate As Variant) As Long
Thanks in advance. Pete

When you pass a parameter to a procedure or function Access can
either simply point to the existing variable or make a local copy
of the contents (value) of the variable for the procedure to use.
Pointing to the variable allows the programmer to modify the
contents of the variable, (this is the way cancel works in the
beforeupdate sub),ByValue makes a separate copy of the variable
for use in the sub, so that you cannot change the value of the
variable in the calling procedure.

Including the ByVal is good programming practice that shows that
you do not want to play with the calling procedure's variable.

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #2

P: n/a
Ptbrady wrote:
What does "ByVal" mean? I couldn't find it in the Access help messages.


Which version of Access? It is in my help. Or maybe the wrong help had
focus? Sit in some module, or even the Debug window, type the word ByVal
and press F1,.

ByVal passes the *value* of the variable to the function. That function
can then not change the variable.

The opposite, ByRef, is default and can be omitted. ByRef passes a
*pointer* to the variable, so its value can actually be changed by the
calling routine. You don't usually do this; occasionally it may come in
very handy.

ByRef is a little more efficient when you pass strings, as with ByVal
the whole string must be copied.

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #3

P: n/a
Bob Quintal wrote:
Including the ByVal is good programming practice that shows that
you do not want to play with the calling procedure's variable.


Stylistically I agree; out of performance view I got back from this.
Passing strings of over 32K many times (or, worse, tree-like object
structures) really is faster with ByRef.

Now that I write this: is ByVal at all possible for objects?

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #4

P: n/a
rkc
Bas Cost Budde wrote:
Bob Quintal wrote:
Including the ByVal is good programming practice that shows that you
do not want to play with the calling procedure's variable.

Stylistically I agree; out of performance view I got back from this.
Passing strings of over 32K many times (or, worse, tree-like object
structures) really is faster with ByRef.

Now that I write this: is ByVal at all possible for objects?


Yes, but if all you change are the properties of the object then
there is no difference between ByVal and ByRef. The change will
be reflected on return either way.

If you set the passed object to a different object the change isn't
reflected on return when passed ByVal.

Nov 13 '05 #5

P: n/a
It means you're sending a COPY of the value, not a REFERENCE to the
variable's location, so you cannot modify it accidentally in your code.
Welcome to the help file and happy reading. May you two remain
friends for a long time.

Nov 13 '05 #6

P: n/a
Thank you for all your replies to my ByVal question. I will now be sure to
include it in my functions so I don't screw things up.
Pete
Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.