Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Iterate over Collection Objects in Container.
Is it possible to Set an object to a string reference?
No. A String is not an object in VB. You can *add* a String to a Collection or assign a String to a String or Variant property of an object.. collectionobject.Add "some string" label.Caption = "some string" -- Bob Kilmer "Paul M" wrote in message ... Hi, I have a question that I hope can be answered quickly. I'm sure there must be a way of doing it. I have three Public Collections dimmed in a Sub. I have a For Each statement iterating over the controls on a form returning List Boxes with Selected Items. I can get the controls to iterate, but can't get the Collections to change as well. Basically, the Control Name is the Collection Name Mid(4) So: Control Name = lbxOwner Collection Name = Owner or Preferably colOwner if possible to add col & the mid statement. The problems is I dim the Control.Name as a variable called ActColName as String, but I can't set the object (ActCollection) as Collection because of the string dimension. Is it possible to Set an object to a string reference? In the immediate window if you type: Set actCollection = colOwner It works But you get an Object Error if you try Set actCollection = ActColName (Where ActColName = colOwner as String) Here is the sample code (Including only the Dimensions referenced here) Public colOwner As New Collection Public colCoOrdinator As New Collection Public colAdministration As New Collection Dim Item As Collection Dim ListIndex As Variant Dim i As Control Dim ActControl As Object Dim ActCollection As Collection Dim ActColName As Variant Dim itemSelected As Boolean For Each i In fmDivReport.Controls If i.Name Like "lbx*" Then ActColName = "col" & Mid(i.name, 4) Set ActControl = i Set ActCollection = ActColName ' This is where it errors For ListIndex = 0 To ActControl.listCount - 1 If ActControl.Selected(ListIndex) = True Then ActCollection.Add ListIndex Debug.Print ActControl.Name & " " & ActControl.List(ListIndex) itemSelected = True End If Next ListIndex End If ListIndex = 0 Next i ----- Any help would be great. Many Thanks in Advance Paul M. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Iterate over Collection Objects in Container.
Thanks for your reply Bob.
I thought as much, but just can't figure out how to side step the problem. The issue is that the collection is named: colOwner The List Box is named: lbxOwner All I need is that the selections from each listbox on the page be defined in it's own collection, but I need to programatically iterate over the list boxes on the form. If I set the Variable Collection (ActCollection) Name to: set ActCollection = colOwner , the problem is alleviated, exccept that I need to itearate the collection object when the Listbox is completed. It sets the object (obviously), but in this case I need to set the object from a concatenated value col (Just a simple prefix for Collection) Mid (i.Name, 4) = Owner ConCat Value = colOwner So the ActCollection needs to be set to the final concatenated value of colOwner (Where i.Name returns the active control lbxOwner or any other lbx on the form). Do you have any ideas how I can achieve this. I've tried storing the string in a container, but as you identified it's not an object. But the blasted string is the object name to use...... Is it possible to Re-Dim?, Use an array of collection names? (I'll try that last option and see how I go) Alternativly, how can you identify Collection Objects contained within the procedure? Any help would be great. Paul M. -----Original Message----- Is it possible to Set an object to a string reference? No. A String is not an object in VB. You can *add* a String to a Collection or assign a String to a String or Variant property of an object.. collectionobject.Add "some string" label.Caption = "some string" -- Bob Kilmer "Paul M" wrote in message ... Hi, I have a question that I hope can be answered quickly. I'm sure there must be a way of doing it. I have three Public Collections dimmed in a Sub. I have a For Each statement iterating over the controls on a form returning List Boxes with Selected Items. I can get the controls to iterate, but can't get the Collections to change as well. Basically, the Control Name is the Collection Name Mid (4) So: Control Name = lbxOwner Collection Name = Owner or Preferably colOwner if possible to add col & the mid statement. The problems is I dim the Control.Name as a variable called ActColName as String, but I can't set the object (ActCollection) as Collection because of the string dimension. Is it possible to Set an object to a string reference? In the immediate window if you type: Set actCollection = colOwner It works But you get an Object Error if you try Set actCollection = ActColName (Where ActColName = colOwner as String) Here is the sample code (Including only the Dimensions referenced here) Public colOwner As New Collection Public colCoOrdinator As New Collection Public colAdministration As New Collection Dim Item As Collection Dim ListIndex As Variant Dim i As Control Dim ActControl As Object Dim ActCollection As Collection Dim ActColName As Variant Dim itemSelected As Boolean For Each i In fmDivReport.Controls If i.Name Like "lbx*" Then ActColName = "col" & Mid(i.name, 4) Set ActControl = i Set ActCollection = ActColName ' This is where it errors For ListIndex = 0 To ActControl.listCount - 1 If ActControl.Selected(ListIndex) = True Then ActCollection.Add ListIndex Debug.Print ActControl.Name & " " & ActControl.List(ListIndex) itemSelected = True End If Next ListIndex End If ListIndex = 0 Next i ----- Any help would be great. Many Thanks in Advance Paul M. . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
series objects; finding specific ones in the collection | Charts and Charting in Excel | |||
SOLVER does not iterate / work | Excel Discussion (Misc queries) | |||
Using Container in Auto open macro | Excel Discussion (Misc queries) | |||
Iterate Circular Reference | Excel Discussion (Misc queries) | |||
Excel funtion to find how many boxes in larger container | Excel Worksheet Functions |