Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Object: smart way to assign a value as for an array?

Hello

quick question: is there a smart way to define a procedure to do the
same thing as a "public let", but with the array syntax?

i.e. you can easily do MyObject.MyValue = 10 with a "public let", but
is there a way to do:

MyObject.MyArray(3)=10

Thanks in advance
Charles

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Object: smart way to assign a value as for an array?

Forgot to mention that I am using VBA

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Object: smart way to assign a value as for an array?

And since Christmas is coming, what about having also the flexibility
to use it in the other way, i.e. xx = MyObject.MyArray(3)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Object: smart way to assign a value as for an array?

Based on a wild guess as to at what you're doing, arrays cannot be Public in
a Class module. Maybe something like -

' code in Class1
Private arr(1 To 10) As Long

Public Property Let propArray(idx As Long, n As Long)
arr(idx) = n
End Property

Public Property Get propArray(idx As Long) As Long
propArray = arr(idx)
End Property


' code in a normal module
Dim myObject As Class1

Sub test()
Set myObject = New Class1

myObject.propArray(3) = 10

MsgBox myObject.propArray(3)

Set myObject = Nothing

End Sub


Regards,
Peter T

"Charles" wrote in message
oups.com...
Hello

quick question: is there a smart way to define a procedure to do the
same thing as a "public let", but with the array syntax?

i.e. you can easily do MyObject.MyValue = 10 with a "public let", but
is there a way to do:

MyObject.MyArray(3)=10

Thanks in advance
Charles



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Object: smart way to assign a value as for an array?

Peter

thanks for your answer. This is exactly what I wanted to do. I wasn't
aware that by defining the procedure "Public Property Let
propArray(idx As Long, n As Long)" you could also use it by doing
"myObject.propArray(3) = 10" instead of something like
"myObject.propArray(3,10)" . It is much more intuitive to use your
way.

Thanks very much!

Charles




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
Assign name to chart object? [email protected] Excel Programming 1 October 18th 06 09:35 PM
assign objects into array or object variable? Fendic[_12_] Excel Programming 1 July 22nd 05 09:23 PM
Can't assign a textbox to object colin.. Excel Programming 4 December 9th 04 03:35 AM
Can't assign a textbox to object colin.. Excel Programming 0 December 8th 04 06:41 PM
assign the sub to the object event Marek Excel Programming 1 September 13th 04 08:50 PM


All times are GMT +1. The time now is 09:46 AM.

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"