Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Grd Grd is offline
external usenet poster
 
Posts: 118
Default ByRef vs ByVal

Hi there,

I have the following code (its simplified). I want to pass a value to a
routine and for it to be doubled. I thought by using ByRef it would come back
to the oriingal routine changed but I must be missing something. I have an
example below. I get 100 instead of 200 at the end of the Test procedure.

What am I doing Wrong.

Any help greatly appreciated.

Tx

Suzanne

Sub Test
Dim y
y =100
Call Test2(y)
Debug.Print y
End Sub

Sub Test2( ByRef x)
x = x *2
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default ByRef vs ByVal

I got 200 in the immediate window.

You may want to copy|paste your exact code--instead of typing the code in the
post.

Grd wrote:

Hi there,

I have the following code (its simplified). I want to pass a value to a
routine and for it to be doubled. I thought by using ByRef it would come back
to the oriingal routine changed but I must be missing something. I have an
example below. I get 100 instead of 200 at the end of the Test procedure.

What am I doing Wrong.

Any help greatly appreciated.

Tx

Suzanne

Sub Test
Dim y
y =100
Call Test2(y)
Debug.Print y
End Sub

Sub Test2( ByRef x)
x = x *2
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
Grd Grd is offline
external usenet poster
 
Posts: 118
Default ByRef vs ByVal

Thanks Dave

So do I now. I must have retyped it and somehow fixed it.
Hooray

Tx again
S

"Dave Peterson" wrote:

I got 200 in the immediate window.

You may want to copy|paste your exact code--instead of typing the code in the
post.

Grd wrote:

Hi there,

I have the following code (its simplified). I want to pass a value to a
routine and for it to be doubled. I thought by using ByRef it would come back
to the oriingal routine changed but I must be missing something. I have an
example below. I get 100 instead of 200 at the end of the Test procedure.

What am I doing Wrong.

Any help greatly appreciated.

Tx

Suzanne

Sub Test
Dim y
y =100
Call Test2(y)
Debug.Print y
End Sub

Sub Test2( ByRef x)
x = x *2
End Sub


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application.run and ByRef arguments AsIs[_3_] Excel Programming 7 November 23rd 06 01:34 PM
ByRef strangeness Nicklas Karlsson Excel Programming 2 October 17th 04 07:36 PM
byref errors Ryan H. Excel Programming 12 August 4th 04 04:44 PM
ByRef question Tommy Flynn[_2_] Excel Programming 2 November 12th 03 01:35 PM
Is ByVal always better if ByRef isn't necessary Jeff[_17_] Excel Programming 5 July 25th 03 09:25 AM


All times are GMT +1. The time now is 10:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"