Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 39,348 times

Contents

Related Categories

Passing Variables By Value or Reference - ByVal vs ByRef

mrjdesign

ByVal vs ByRef

The difference between ByVal and ByRef is very simple once we recall the subject on pointers. These keywords are simply abbreviations of the full definition of the differences between the two.

ByVal = By Value and ByRef = By Reference

Now we can recall what I said in the previous chapter about C/C++ and pointers. Pointers act as a Reference to a memory address location. In VB however, this means that the reference is occurring in your statement directly at the location of the actual data, and where it is stored.

Selecting a ByVal would thereby mean you are only working on a copy or replica of the data, and not the actual data segment it self.

This has specific implications for how your statements can handle and alter the data in your variable. The ByRef use, would imply that a change performed by the statement of the value you pass, has an affect on the actual data, while the ByVal use would only alter the copy the statement has to work on.

Simply described, if passed ByRef, a procedure can permanently alter the data stored in the variable. Since it also is faster to send a memory address location, rather than passing a copy of a data argument, it is the default value used by Visual Basic.


©2001 - All Rights Reserved - MRJ Design
The source code samples and information pertained within this document are considered copyrighted material and may not be re-distributed by electronic or other media in any form or fashion whatsoever, withou

Comments

  • Thanks :)

    Posted by mrjdesign on 05 Feb 2003

    It was fun to write it too... I still havn't gotten the hang on all ins and outs yet but I'm learning as I help others.

  • not that much

    Posted by http://vbxzone.tripo on 20 Nov 2001

    it was not a bad article. However it was kind of too abstract, and no code examples or anything. just pure bs on byref and byval

  • Informative

    Posted by outvit on 28 Oct 2001

    This was a very informative article. It was a pleasure to read.