PDA

View Full Version : Collections Issue



michael.hooker
2009-01-06, 09:23 PM
I have created two collections, colLineNo and AColl.

colLineNo holds a list of line numbers extracted from multiple models using DWGDirectX. In order to maintain the original list of line numbers stored in colLineNo, I set AColl = colLineNo. This is the only place in the code that AColl is filled.

Code snippet for filling colLineNo:

With colLineNo
For nIndex As Integer = 1 To .Count
If .Item(nIndex) = lineNo Then
bfound = True
End If
Next
If Not bfound And lineNo.Length > 0 And lineNo.Contains(Chr(34)) Then
.Add(lineNo)
End If
End With

Code snippet for Filling AColl:

If formLoad = True Then
For I As Integer = 1 To colLineNo.Count
AColl.Add(colLineNo(I).ToString)
Next
End If

As pointed out in the paragraph above I originally set AColl = colLineNo.
I changed to code in the snippet above in case the program was interpreting that AColl and colLineNo were the same collection.

On a separate form I want a listbox to display only the lines associated with each particular model whose names are listed in cmboModels using the code snippet shown below:

If Not cmboModels.SelectedValue = "<All Models>" Then
For x As Integer = myFIOs.GetLowerBound(0) To myFIOs.GetUpperBound(0)
Dim filename As String = myFIOs(x).FullName.ToString
If filename.Contains(cmboModels.SelectedValue) Then
colLineNo.Clear()
Dim myDWG = oApp.Documents.Open(filename)
Application.DoEvents()
frm.GetEntities(myDWG)
End If
Next
Else
colLineNo = AColl
End If

As long as I do not select <All Models> in cmboModels my listbox is filled with the correct line numbers for each model. However, If I select <All Models> I want colLineNo to repopulate with the original list of Line numbers stored in AColl. The problem I am having is with the colLineNo.Clear statement. Not only is colLineNo cleared of its values but AColl is also cleared. Nowhere in code is AColl dimensioned as being collection colLineNo. AColl is dimensioned as a new collection and filled with the original values stored in colLineNo.

I would appreciate it if anyone can give me a better understanding of Collections and why a disassociated collection is cleared as well as the intended collection.