Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create array property for a class?

Status
Not open for further replies.

pbb72

Programmer
Mar 27, 2004
38
NO
Is it possible to create a class property that is of type array? Or is the only solution to create a public array variable in the class? This is what I would like to do:

Code:
class clsTest
  public property get arr
    arr = array(0,1,2,3,4)
  end property
end class

dim test
set test = new clsTest
MsgBox(test.arr(0)) ' error...
 
Try this instead.
[tt]
dim test, x
set test = new clsTest
x=test.arr
MsgBox x(0)
[/tt]
- tsuji
 
Hmmm yeah, not a very nice solution isn't it :-(
 
I do not disagree! How about alternative way to conceive the thing.
[tt]
class clsTest
private arr_private
private sub class_initialize
redim arr_private(4)
arr_private(0)=0
arr_private(1)=1
arr_private(2)=2
arr_private(3)=3
arr_private(4)=4
end sub

public property get arr(i)
arr = arr_private(i)
end property
end class

dim test
set test = new clsTest
MsgBox(test.arr(0))
MsgBox(test.arr(1))
[/tt]
- tsuji
 
Yeah, I've also thought about that second solution, except there was one big problem; I also want to read out the UBound of the array!
Using a public array variable in the class came closest to what I wanted, except that the class contains many optional arrays that take a long time to generate, so I wanted to generate them upon request...
 
Then the first solution is not that bad. When you think about it, it makes sense. It takes out the ambiguity of the parameter as index or as argument to a method.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top