I am writting an app to collect attributes from a block. I have a simple class named AttInf (see below). In a form module I have a procedure that finds the insertion, and adds each attribute to another class instance that is not much more than a collection of AttInf instances (see class Attributes, below).
The issue I'm having is with the Add method in the Attributes class. The routine that cycles through the attributes works fine, calling the Add method of the Attributes class with the correct argument each time. However, when I step into the Add method, each attinf in the atts collection takes on the properties of the attinf sent as the argument to the add method. I don't understand how this can happen, nor what to do to solve the problem.
Suggestions are much appreciated.
Mike Weaver
Class AttInf
Option Explicit
Public TagString As String
Public Value As String
Public Handle As String
'Simple enough?
Calling Procedure
For Each objTarget In objPSpace
If objTarget.ObjectName = "AcDbBlockReference" Then
If (objTarget.Name = InsertName) And (objTarget.HasAttributes = True) Then
Dim Atts As Variant
Atts = objTarget.GetAttributes
Dim i As Integer
For i = LBound(Atts) To UBound(Atts)
Set ThisAtt = Atts(i)
attThis.TagString = ThisAtt.TagString
attThis.Value = ThisAtt.TextString
attThis.Handle = ThisAtt.Handle
Attribs.Add attThis '<<<<<<<<<<<<<<<---------------------<<< This is where I'm having the problem
Next i
GetAttributeInfo.PathName = PathName
GetAttributeInfo.Attribs = Attribs
Exit Function
End If
End If
Next objTarget
Class Attributes
Option Explicit
Private Atts As collection
Private Sub Class_Initialize()
Set Atts = New collection
End Sub
Private Sub Class_Terminate()
Set Atts = Nothing
End Sub
...
Public Sub Add(AttNew As AttInf)
Dim i As Integer
For i = 1 To Atts.Count
If Atts.Item(i).TagString = AttNew.TagString And Atts.Item(i).Handle = AttNew.Handle Then
Atts.Item(i).Value = AttNew.Value
Else
Atts.Add AttNew
Exit Sub
End If
Next i
Atts.Add AttNew
End Sub