Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default ByRef not passing address

Hope some one can help

My problem is when I try to create a function that will increment an
integer, the calling parameter I believe is passed as a value and not a
reference. The help file suggest that default value of parameters passed is
ByRef, but this example tell me in the case of integer its not.

Does any one have a work around.

My email address is
All suggests are welcomed. A coded example would explain all


Program
dim myValue as integer
.....
myValue = 0
increment(myValue)
' here myValue still has value of 0, because it was not passed to
subroutine as reference and hence not incremented
....
end Program



sub increment( number as integer)
number = number + 1
end sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default ByRef not passing address

This shows passing by ref is in affect:

Sub One()
Dim X As Integer
Two X
MsgBox X
End Sub

Sub Two(Y As Integer)
Y = Y + 1
End Sub


--
Jim Rech
Excel MVP


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default ByRef not passing address

Ian,
Your causing the problem yourself by incorrectly calling the function.

increment(myValue)

shoud be

increment myValue

You only use parentheses if you are returning a value (calling a function)
or you are using Call

Call Increment(myValue)

--
Regards,
Tom Ogilvy


"Ian Stanborough" wrote in message
...
Hope some one can help

My problem is when I try to create a function that will increment an
integer, the calling parameter I believe is passed as a value and not a
reference. The help file suggest that default value of parameters passed

is
ByRef, but this example tell me in the case of integer its not.

Does any one have a work around.

My email address is
All suggests are welcomed. A coded example would explain all


Program
dim myValue as integer
.....
myValue = 0
increment(myValue)
' here myValue still has value of 0, because it was not passed to
subroutine as reference and hence not incremented
....
end Program



sub increment( number as integer)
number = number + 1
end sub




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
How do I avoid excel change absolute address to relative address Miguel Excel Discussion (Misc queries) 3 May 10th 07 11:18 PM
How do I import Office address book to Outlook Express address bo. snnorp Excel Discussion (Misc queries) 2 February 22nd 05 11:47 AM
Passing Cell Address to Offset Bob Excel Worksheet Functions 2 December 1st 04 04:56 PM
LINKING Address cells from an EXCEL spreadsheet to fill MapQuest Address Info Duane S. Meyer Excel Programming 0 August 30th 03 12:16 AM
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:26 PM.

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"