An item is added to a list using the Add method. By adding an item to a list we are adding a reference to that item in the list. This should not be confused with the Add methods of the collection object that create new items within the design. To complement this method, the Remove method is used to remove items from the list.
The Marker and Surface lists require a variant parameter to define the reference of the items being added or removed from the list. There are several ways to define which items are being added to the list. These are shown in the following code examples.
Sub AddingItems()
Dim msDesign As Maxsurf.Design
Set msDesign = msApp.Design
Dim mList As New Maxsurf.MarkerList
'Adding a marker already in the list will create an error
'This line will handle that error and move on
On Error Resume Next
'Add marker 1
mList.Add 1
'Add Markers 2,3,4,5
mList.Add "2,3,4,5"
'Add Markers 6 through 10
mList.Add "6-10"
'Add Marker 11 using the markers object
mList.Add msDesign.Markers(11)
'Clear the entire List
mList.Clear
'Add every marker in the collection
mList.Add msDesign.Markers
End Sub
The clear method is also used in the above code, to remove all markers from the list.
Items within the list can be accessed in the same way as items within a collection, using an item number; the following code will store all the height values for the marker list into the C column of the current Excel sheet.
Sub AccessItems()
Dim msDesign As Maxsurf.Design
Set msDesign = msApp.Design
Dim mList As New Maxsurf.MarkerList
mList.Add msDesign.Markers
For i = 1 To mList.Count
Cells(i + 10, 3) = mList(i).Height
Next
End Sub
List and Collection Item Numbers
Care needs to be taken when accessing elements in a List. The item reference used in the list is for that list. The MarkerList element 6 will be the 6th marker in the list, not the 6th marker in the collection.