Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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
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
series objects; finding specific ones in the collection cate Charts and Charting in Excel 2 April 4th 10 03:25 PM
SOLVER does not iterate / work BHatMJ Excel Discussion (Misc queries) 4 August 12th 09 10:42 PM
Using Container in Auto open macro [email protected] Excel Discussion (Misc queries) 0 November 9th 06 11:22 AM
Iterate Circular Reference Brandt Excel Discussion (Misc queries) 1 August 3rd 05 11:43 PM
Excel funtion to find how many boxes in larger container logistics learner Excel Worksheet Functions 3 December 21st 04 01:18 AM


All times are GMT +1. The time now is 01:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"