473,471 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What does ByVal mean?

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
6 25283
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Ptbrady | last post by:
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...
0
by: Sjaakie Helderhorst | last post by:
Hi all, I'm trying to create a class which handles FTP. Knowing little of classes I'm having some trouble making things work. Also having trouble finding the meaning of some error-codes. The code...
2
by: Tom | last post by:
I'm getting this error when I try to pass a structure to a dll. An unhandled exception of type 'System.ArgumentException' occured in Test1.exe Additional Information: Type could not be marshaled...
8
by: kevin | last post by:
I have a form and in the form I have a sub that uses a class I instantiate using visual basic code: Public oCP As New Rs232 'instantiate the comm port I need to share this sub with...
4
by: Supra | last post by:
in vb 6 in class project: Private varNewChan As Collection 'new channel window withevents procedure events: Private Sub RFC_Ob_onNickJoin(ByVal szNick As String, ByVal szHost As String, ByVal...
3
by: Frustrated Developer via DotNetMonster.com | last post by:
I have developed a form that would allow the user to load and search a database several ways, by data range, by specific number or all database entries. I can successfully load any of the ways...
52
by: Julie | last post by:
I'm supporting an application at work. Below are some code segments that I can't understand how they work. First let me say, I would never code this standard. I'm just really creeped out that it...
13
by: Herman Jones | last post by:
I found this statement in some sample code. It seems to be syntactically correct. What do the brackets around "String" mean? Dim sWork As = "Some number of characters"
12
by: Marc | last post by:
Comming from JSP-HTML when I hear 'script' I think of JavaScript or perhaps VBScript. But I think in ASP.NET they mean something else? I am bit confused now. Reading a book I see the following:...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.