Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Object Arrays
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Object Arrays
What is it all for?
Where is the array? Why do want an object? RBS "Phantom" wrote in message oups.com... 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. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Object Arrays
Hi Dave ~
Thanks. Yeah, I'm trying to create menu items. I have 5 case levels with pretty much the same code as I mentioned. I wanted to make it more efficient and go through a "for" loop and assign the menu item or commandbar to 1 particular array item. So, I have 5 menu levels: 1 being the top parent node and the consecutive numbers is it's child nodes. For 1 to 5, I check if there is a child node for each of the numbers and then assign a caption, faceid. I originally had it this way (which I know is not efficient): [Begin Code] Select Case MenuLevel Case 1 ' A Menu ' Add the top-level menu to the Worksheet CommandBar Set MenuObject = Application.CommandBars(1). _ Controls.Add(Type:=msoControlPopup, _ befo=PositionOrAction, _ temporary:=True) MenuObject.Caption = Caption Case 2 ' A Menu Item If NextLevel = 3 Then Set MenuItem = _ MenuObject.Controls.Add(Type:=msoControlPopup) Else Set MenuItem = _ MenuObject.Controls.Add(Type:=msoControlButton) MenuItem.OnAction = PositionOrAction End If MenuItem.Caption = Caption If FaceId < "" Then MenuItem.FaceId = FaceId If Divider Then MenuItem.BeginGroup = True Case 3 ' A SubMenuLevel1 Item If NextLevel = 4 Then Set SubMenuLev1Item = _ MenuItem.Controls.Add(Type:=msoControlPopup) Else Set SubMenuLev1Item = _ MenuItem.Controls.Add(Type:=msoControlButton) 'SubMenuLev1Item.OnAction = PositionOrAction End If SubMenuLev1Item.Caption = Caption If FaceId < "" Then SubMenuLev1Item.FaceId = FaceId If Divider Then SubMenuLev1Item.BeginGroup = True Case 4 ' A SubMenuLevel2 Item If NextLevel = 5 Then Set SubMenuLev2Item = _ SubMenuLev1Item.Controls.Add(Type:=msoControlPopup ) Else Set SubMenuLev2Item = _ SubMenuLev1Item.Controls.Add(Type:=msoControlButto n) 'SubMenuLev2Item.OnAction = PositionOrAction End If SubMenuLev2Item.Caption = Caption If FaceId < "" Then SubMenuLev2Item.FaceId = FaceId If Divider Then SubMenuLev2Item.BeginGroup = True Case 5 ' A SubMenuLevel3 Item Set SubMenuLev3Item = _ SubMenuLev2Item.Controls.Add(Type:=msoControlButto n) SubMenuLev3Item.Caption = Caption 'SubMenuLev3Item.OnAction = PositionOrAction If FaceId < "" Then SubMenuLev3Item.FaceId = FaceId If Divider Then SubMenuLev3Item.BeginGroup = True End Select [End of code] I'm hoping that your code will simplify this much better. Or is there a more simplified version? Thank you so much for all your help. Denny. Dave Peterson wrote: 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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Object Arrays
This looks a lot like the code from John Walkenbach's MenuMaker routine. He
keeps the values in a worksheet and loops through the rows in that worksheet. (In case it's not based on John's code, you may want to see how he does it: http://j-walk.com/ss/excel/tips/tip53.htm.) Personally, I find that very efficent--both in programming and in concept. It really makes it easy to update. Phantom wrote: Hi Dave ~ Thanks. Yeah, I'm trying to create menu items. I have 5 case levels with pretty much the same code as I mentioned. I wanted to make it more efficient and go through a "for" loop and assign the menu item or commandbar to 1 particular array item. So, I have 5 menu levels: 1 being the top parent node and the consecutive numbers is it's child nodes. For 1 to 5, I check if there is a child node for each of the numbers and then assign a caption, faceid. I originally had it this way (which I know is not efficient): [Begin Code] Select Case MenuLevel Case 1 ' A Menu ' Add the top-level menu to the Worksheet CommandBar Set MenuObject = Application.CommandBars(1). _ Controls.Add(Type:=msoControlPopup, _ befo=PositionOrAction, _ temporary:=True) MenuObject.Caption = Caption Case 2 ' A Menu Item If NextLevel = 3 Then Set MenuItem = _ MenuObject.Controls.Add(Type:=msoControlPopup) Else Set MenuItem = _ MenuObject.Controls.Add(Type:=msoControlButton) MenuItem.OnAction = PositionOrAction End If MenuItem.Caption = Caption If FaceId < "" Then MenuItem.FaceId = FaceId If Divider Then MenuItem.BeginGroup = True Case 3 ' A SubMenuLevel1 Item If NextLevel = 4 Then Set SubMenuLev1Item = _ MenuItem.Controls.Add(Type:=msoControlPopup) Else Set SubMenuLev1Item = _ MenuItem.Controls.Add(Type:=msoControlButton) 'SubMenuLev1Item.OnAction = PositionOrAction End If SubMenuLev1Item.Caption = Caption If FaceId < "" Then SubMenuLev1Item.FaceId = FaceId If Divider Then SubMenuLev1Item.BeginGroup = True Case 4 ' A SubMenuLevel2 Item If NextLevel = 5 Then Set SubMenuLev2Item = _ SubMenuLev1Item.Controls.Add(Type:=msoControlPopup ) Else Set SubMenuLev2Item = _ SubMenuLev1Item.Controls.Add(Type:=msoControlButto n) 'SubMenuLev2Item.OnAction = PositionOrAction End If SubMenuLev2Item.Caption = Caption If FaceId < "" Then SubMenuLev2Item.FaceId = FaceId If Divider Then SubMenuLev2Item.BeginGroup = True Case 5 ' A SubMenuLevel3 Item Set SubMenuLev3Item = _ SubMenuLev2Item.Controls.Add(Type:=msoControlButto n) SubMenuLev3Item.Caption = Caption 'SubMenuLev3Item.OnAction = PositionOrAction If FaceId < "" Then SubMenuLev3Item.FaceId = FaceId If Divider Then SubMenuLev3Item.BeginGroup = True End Select [End of code] I'm hoping that your code will simplify this much better. Or is there a more simplified version? Thank you so much for all your help. Denny. Dave Peterson wrote: 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 -- Dave Peterson |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Object Arrays
Hi Dave ~
You're right. I did get it from John's code, but I wanted to simplify it a bit more. I have a few more levels with the same code. So, that's why I wanted to make it into an array for efficiency. Let me try your way and see if it works. Thanks, Denny ~ Dave Peterson wrote: This looks a lot like the code from John Walkenbach's MenuMaker routine. He keeps the values in a worksheet and loops through the rows in that worksheet. (In case it's not based on John's code, you may want to see how he does it: http://j-walk.com/ss/excel/tips/tip53.htm.) Personally, I find that very efficent--both in programming and in concept. It really makes it easy to update. Phantom wrote: Hi Dave ~ Thanks. Yeah, I'm trying to create menu items. I have 5 case levels with pretty much the same code as I mentioned. I wanted to make it more efficient and go through a "for" loop and assign the menu item or commandbar to 1 particular array item. So, I have 5 menu levels: 1 being the top parent node and the consecutive numbers is it's child nodes. For 1 to 5, I check if there is a child node for each of the numbers and then assign a caption, faceid. I originally had it this way (which I know is not efficient): [Begin Code] Select Case MenuLevel Case 1 ' A Menu ' Add the top-level menu to the Worksheet CommandBar Set MenuObject = Application.CommandBars(1). _ Controls.Add(Type:=msoControlPopup, _ befo=PositionOrAction, _ temporary:=True) MenuObject.Caption = Caption Case 2 ' A Menu Item If NextLevel = 3 Then Set MenuItem = _ MenuObject.Controls.Add(Type:=msoControlPopup) Else Set MenuItem = _ MenuObject.Controls.Add(Type:=msoControlButton) MenuItem.OnAction = PositionOrAction End If MenuItem.Caption = Caption If FaceId < "" Then MenuItem.FaceId = FaceId If Divider Then MenuItem.BeginGroup = True Case 3 ' A SubMenuLevel1 Item If NextLevel = 4 Then Set SubMenuLev1Item = _ MenuItem.Controls.Add(Type:=msoControlPopup) Else Set SubMenuLev1Item = _ MenuItem.Controls.Add(Type:=msoControlButton) 'SubMenuLev1Item.OnAction = PositionOrAction End If SubMenuLev1Item.Caption = Caption If FaceId < "" Then SubMenuLev1Item.FaceId = FaceId If Divider Then SubMenuLev1Item.BeginGroup = True Case 4 ' A SubMenuLevel2 Item If NextLevel = 5 Then Set SubMenuLev2Item = _ SubMenuLev1Item.Controls.Add(Type:=msoControlPopup ) Else Set SubMenuLev2Item = _ SubMenuLev1Item.Controls.Add(Type:=msoControlButto n) 'SubMenuLev2Item.OnAction = PositionOrAction End If SubMenuLev2Item.Caption = Caption If FaceId < "" Then SubMenuLev2Item.FaceId = FaceId If Divider Then SubMenuLev2Item.BeginGroup = True Case 5 ' A SubMenuLevel3 Item Set SubMenuLev3Item = _ SubMenuLev2Item.Controls.Add(Type:=msoControlButto n) SubMenuLev3Item.Caption = Caption 'SubMenuLev3Item.OnAction = PositionOrAction If FaceId < "" Then SubMenuLev3Item.FaceId = FaceId If Divider Then SubMenuLev3Item.BeginGroup = True End Select [End of code] I'm hoping that your code will simplify this much better. Or is there a more simplified version? Thank you so much for all your help. Denny. Dave Peterson wrote: 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 -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Confusion about how the Window object fits into the Excel object model | Excel Programming | |||
Object arrays on forms | Excel Programming | |||
Object Arrays | Excel Programming | |||
Object Arrays | Excel Programming | |||
Object Arrays | Excel Programming |