LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Pass object by value not working...

Hi all,

Is there any way to pass an object (created from a custom Class) by
Value in VBA..? I have tried using the ByVal keyword in my procedure
but the object is still being passed by reference (the original object
is modified in the procedure code). Here's my code:

For the Class module (called Test):

Private classVar1 As String

Property Get Number() As String
Number = classVar1
End Property

Property Let Number(ByVal newvalue As String)
classVar1 = newvalue
End Property

In the main Module:

Private Test1 As Test

Private Sub Initiate()
Set Test1 = New Test
Let Test1.Number = "1"

Call AnotherSub(Test1)

MsgBox Test1.Number 'Shows 2 not 1 even though it should be passed
ByVal, not ByRef
End Sub

Private Sub AnotherSub(ByVal t As Test)
Let t.Number = "2"
End Sub

How do I force VBA to pass this Class ByVal or can't it be done..?

Thanks,
Lyndon.

 
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
Working with the range object [email protected] Excel Discussion (Misc queries) 1 November 26th 07 04:29 PM
Working with a Range object LF Excel Programming 14 December 12th 06 05:45 AM
Pass a form Listbox as an object Brian Excel Programming 2 November 18th 05 11:51 PM
fileformat not working with Object Nancy[_4_] Excel Programming 1 September 27th 04 01:35 PM
How to pass valve in combobox object to cell chanon Excel Programming 3 October 15th 03 04:25 AM


All times are GMT +1. The time now is 01:30 PM.

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

About Us

"It's about Microsoft Excel"