Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 2nd, 2004, 05:16 PM
Authorized User
 
Join Date: Oct 2004
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default ByRef and ByVal

Can someone explain the difference between ByRef and ByVal using an example. This would be most appreciated.


Reply With Quote
  #2 (permalink)  
Old November 2nd, 2004, 07:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default


public sub XByRef(byref a as long)
''a is a reference to the original caller variable
a = a + 10
exit sub

public sub XByVal(byval a as long)
''a is a just a copy of the original caller variable
a = a + 10
exit sub

using byref, the variable 'a' is increased by 10 in the caller scope. Using byval, it remains the same.

dim a as long
a = 10
call XByVal(a)
'' a is still 10
call XByRef(a)
'' a is now 10

Use ByRef if you want that the method can change the value of the variable when it returns.

Marco
Reply With Quote
  #3 (permalink)  
Old November 2nd, 2004, 08:09 PM
Authorized User
 
Join Date: Oct 2004
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Marco,

Thankyou very much for the example

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ByRef Argument! Apocolypse2005 Beginning VB 6 11 August 9th, 2007 02:21 PM
Passing ADO Recordset ByVal robzyc Access VBA 2 April 23rd, 2007 09:07 AM
ByRef property rolandatem VB.NET 2002/2003 Basics 1 October 8th, 2005 08:42 AM
byRef ? g2000 Classic ASP Basics 0 August 18th, 2005 09:37 AM



All times are GMT -4. The time now is 07:38 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.