[VBA]选择集变量的重复利用问题
我编了一个有关选择集的程序,当第一次执行selectionset1.select mode,,,gpcode,datavalue 程序一切正常,后又用selectionset1.clear将选择集中的成员清除,重新构造选择集,用下面的语句
selectionset1.select mode,,,gpcode1,datavalue1
即:选择的方式没变,但选择的条件变了,程序就老执行不通,错误提示为:运行时错误'5'
"无效的过程调用或参数" , 构造新选择集的参数(新的两数组)肯定是没问题的,但程序到这一步就出错,请大虾帮忙 可能是你多次使用Add方式创建新的选择集,而原来名称的选择集已经存在,就会出错。 目的是除选择集,试试用selectionset1.erase或者delete方法看 安全地创建选择集很重要。给你一个子程序吧:
Public Function CreateSelectionSet(AcadDoc As AcadDocument, ByVal Name As String) As AcadSelectionSet
On Error GoTo ERR_HANDLER
Dim SSetObj As AcadSelectionSet
Dim SSetColl As AcadSelectionSets
Set SSetColl = AcadDoc.SelectionSets
Dim Index As Integer
Dim Found As Boolean
Found = False
For Index = 0 To SSetColl.Count - 1
Set SSetObj = SSetColl.Item(Index)
If StrComp(SSetObj.Name, Name, 1) = 0 Then
Found = True
Exit For
End If
Next
If Not (Found) Then
Set SSetObj = SSetColl.Add(Name)
Else
SSetObj.Clear
End If
Set CreateSelectionSet = SSetObj
Exit Function
ERR_HANDLER:
Debug.Print "Error in Function CreateSelectionSet: " & Err.Number & " -- "; Err.Description
Resume ERR_END
ERR_END:
End Function
页:
[1]