[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<BR> On Error GoTo ERR_HANDLER<BR> <BR> Dim SSetObj As AcadSelectionSet<BR> Dim SSetColl As AcadSelectionSets<BR> Set SSetColl = AcadDoc.SelectionSets<BR> <BR> Dim Index As Integer<BR> Dim Found As Boolean<BR> <BR> Found = False
For Index = 0 To SSetColl.Count - 1<BR> Set SSetObj = SSetColl.Item(Index)<BR> If StrComp(SSetObj.Name, Name, 1) = 0 Then<BR> Found = True<BR> Exit For<BR> End If<BR> Next<BR> <BR> If Not (Found) Then<BR> Set SSetObj = SSetColl.Add(Name)<BR> Else<BR> SSetObj.Clear<BR> End If<BR> <BR> Set CreateSelectionSet = SSetObj<BR> <BR> Exit Function<BR>ERR_HANDLER:<BR> Debug.Print "Error in Function CreateSelectionSet: " & Err.Number & " -- "; Err.Description<BR> Resume ERR_END<BR> <BR>ERR_END:<BR>End Function<BR>
页:
[1]