Message 1 of 3
Accessing items of a newly created collection!

Not applicable
03-02-2001
01:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I created a new collection with the following code:
Private Function GetXrefs() As Collection
Dim BlockList As New Collection
Dim iCount As Long
Dim acadObject As AcadBlock
Dim AcadEnt As AcadEntity
'get list of available blocks
For Each acadObject In ThisDrawing.Blocks
If acadObject.IsXRef = True Then
BlockList.Add acadObject.Name, acadObject.Name
End If
Next
'return list of blocks in this drawing
If BlockList.Count > 0 Then
Set GetXrefs = BlockList
Else
Set GetXrefs = Nothing
End If
Now i want to cycle through that list (collection) and do things to the
xrefs contained within the collection so i try this:
Dim BlockList As Collection
Dim objBlock As AcadBlock
' Get list of blocks
Set BlockList = GetXrefs()
For Each objBlock In BlockList
strXrefname = objBlock.Name
Set objBlock = ThisDrawing.Blocks(strXrefname)
UserForm1.ListBox1.AddItem strXrefname
But something is going wrong at the start of the for each statement where i
get the error message " object required".
so i try setting the objblock variable to the blocklist collection item and
i get "Argument not optional"
set objblock = blocklist.item
Can someone please help.
Private Function GetXrefs() As Collection
Dim BlockList As New Collection
Dim iCount As Long
Dim acadObject As AcadBlock
Dim AcadEnt As AcadEntity
'get list of available blocks
For Each acadObject In ThisDrawing.Blocks
If acadObject.IsXRef = True Then
BlockList.Add acadObject.Name, acadObject.Name
End If
Next
'return list of blocks in this drawing
If BlockList.Count > 0 Then
Set GetXrefs = BlockList
Else
Set GetXrefs = Nothing
End If
Now i want to cycle through that list (collection) and do things to the
xrefs contained within the collection so i try this:
Dim BlockList As Collection
Dim objBlock As AcadBlock
' Get list of blocks
Set BlockList = GetXrefs()
For Each objBlock In BlockList
strXrefname = objBlock.Name
Set objBlock = ThisDrawing.Blocks(strXrefname)
UserForm1.ListBox1.AddItem strXrefname
But something is going wrong at the start of the for each statement where i
get the error message " object required".
so i try setting the objblock variable to the blocklist collection item and
i get "Argument not optional"
set objblock = blocklist.item
Can someone please help.