Thread: Object Arrays
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Object Arrays

It sounds like you want a two dimensional array--one dimension to hold the
..caption and one dimension to hold the .faceid.

Option Explicit
Sub testme02()
Dim myHolderOfObjectStuff() As Variant
Dim oCtr As Long
Dim myObj As Object

oCtr = 0
For Each myObj In SomeSetOfObjects '???some commandbar???
oCtr = oCtr + 1
ReDim Preserve myHolderOfObjectStuff(1 To 2, 1 To oCtr)

myHolderOfObjectStuff(1, oCtr) = myObj.Caption
myHolderOfObjectStuff(2, oCtr) = myObj.FaceId
Next myObj
End Sub

Or you could create a single dimension array and keep track this way:

Option Explicit
Type myObjStuff
myCaption As String
myFaceId As Long
End Type
Sub testme03()

Dim myArray() As myObjStuff
Dim myObj As Object
Dim oCtr As Long

For Each myObj In SomeSetOfObjects 'some commandbar???
oCtr = oCtr + 1
ReDim Preserve myArray(1 To oCtr)
myArray.myCaption = myObj.Caption
myArray.myFaceId = myObj.FaceId
Next myObj

End Sub




Phantom wrote:

Hi ~

I've been racking my brain on this for over an hour. I want to create
a dynamic object array that will save the caption and faceid to an
assigned array. It seems pretty straight forward, but I can't seem to
figure it out. Here's a sample of my code:
Dim myObject As Object
for x = 1 to 2
Select Case Level
Case 1
myObject.Caption = "aaaa"
myObject.FaceId = 321
Case 2
myObject.Caption = "bbbb"
myObject.FaceId = 423
End Select
If you can provide any help on this, I would greatly appreciate it.

Thanks,

Denny.


--

Dave Peterson