mark 发表于 2006-10-16 14:06:17

调试错误(参数不正确)

让我看看能不能解释一下。我有一个功能
Public Function PointTest(Pt As Long) As Boolean
   
    If getCivilObjects = False Then
      Exit Function
    End If
   
    Dim oPoint As AeccPoint
   
    Set oPoint = AllPoints.Find(Pt)<== debug stops here, value of 'oPoint' is "Nothing"
   
    If oPoint Is Nothing Then
      MsgBox "point not found"
    End If如果我使用有效的点编号(dwg中的一个)运行,它可以正常工作'oPoint#039;是一个对象(aeccpoint)。如果使用无效点运行它,则会出现调试错误&引用;参数不正确
从文件中
此时I#039;我完全糊涂了
谢谢

mark 发表于 2006-10-16 14:22:33

“The”;“本地人”;对话框包含此信息

Jeff_M 发表于 2006-10-16 14:47:34

您只需要知道,如果点不存在,Find方法会抛出错误,并为其设置plqan。这里是#039;这是我的PackPoints宏中的一个片段,它正是这样做的:
On Error Resume Next
For I = iStPnt To iEndPnt
    Set oPoint = cPoints.Find(I)
    If Err.Number = 0 Then
      If oPoint.Number = iStPnt Then
            iStPnt = iStPnt + 1
      Else
            J = J + 1
            lPnts(J) = I
      End If
    Else
      Err.Clear 'just clear the error, I need not do anything with it
    End If
Next I
现在,我知道有些人更喜欢将错误发送给错误处理程序,但在这种情况下,我只希望将其在线处理,因为这是这段代码中唯一可能出现的错误。

DinØsaur 发表于 2006-10-16 14:54:33

马克,除非你想要学习体验,否则在你投入大量时间之前,你可能想查看Civil 3D提供的查询&nbsp;我有一个屏幕截图附加,但它是大的方式-一个非常漂亮的工具!

mark 发表于 2006-10-16 15:02:16


谢谢杰夫。

mark 发表于 2006-10-16 15:10:11


实际上是&#039;这就是为什么我&#039;我在写这个应用程序&nbsp;我确实试过了,但它&#039;对我来说,这是一种放慢速度的方法,对我来说是一种很好的方法。我真的很想学习VBA,那就是&#039;这就是为什么我&#039;我正在写这个应用程序
谢谢史蒂夫。

mark 发表于 2006-10-16 15:21:41

查看一些示例代码和文档,他们似乎希望您使用;ContainsPoint方法“;在“中”;AeccPointGroup

mark 发表于 2006-10-16 15:49:18

这是可行的
Public Function GroupsTest()
    If getCivilObjects = False Then
      GroupsTest = False
      Exit Function
    End If
   
    Dim oGroups As AeccPointGroups
    Set oGroups = AeccDoc.PointGroups
   
    Dim oGroup As AeccPointGroup
    Set oGroup = oGroups.Item("_All Points")
   
    If oGroup.ContainsPoint(9999) Then '9999 is not in the dwg
      GroupsTest = True
    Else
      MsgBox "point not found"
    End If
   
End Function

Jeff_M 发表于 2006-10-16 16:15:09

虽然这肯定是该方法的一个用途,但在我看来,如果你不首先与团队合作,这似乎是一种耗时的消遣。(如果你只是在点之间反转,你就不会这样做。)
只要确定Find(pt)是否抛出错误,就可以在不访问组/组的情况下执行相同的操作。由于无论如何都需要使用Find(pt)来访问点#039;s属性。。。。。。。

mark 发表于 2006-10-16 17:49:38

马克,你喜欢这份工作吗
这是一个我通常使用的错误处理程序示例:
Public Function PointTest(Pt As Long) As Boolean
    On Error Goto ErrorHandler
       
    If getCivilObjects = False Then
      Exit Function
    End If
   
    Dim oPoint As AeccPoint
   
    Set oPoint = AllPoints.Find(Pt)'Need to catch the error number that was thrown here.
   
    If oPoint Is Nothing Then
      MsgBox "point not found"
    End If
       
        'bunch of stuff here
ExitHere:
        'clean up any references...
        set oPoint = nothing
       
       
        exit function
ErrorHandler:
        select case Err.number
        case -22222 '<-This would be where the error that is thrown from the .Find method
                resume next 'resume on the line following where the error was thrown
        case else
                msgbox "Something just happened..."
        end select
       
        resume ExitHere
end function
页: [1] 2
查看完整版本: 调试错误(参数不正确)