Author Topic: debug error ( paremeter is incorrect )  (Read 3486 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
debug error ( paremeter is incorrect )
« on: October 16, 2006, 02:06:17 PM »
Let me see if I can explain this. I have a function;

Code: [Select]
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

that if I run with a valid point number ( one that's in the dwg ) it works fine. 'oPoint' is an object ( aeccpoint ). If I run it with an invalid point I get the debug error. "paremeter is incorrect".

from the docs
Quote
IAeccPoints:: Find Method
IAeccPoints InterfaceGets the point with the given point number from the collection.

HRESULT Find(
[in] long PointNumber,
[out, retval] IAeccPoint ** pVal
);

Parameters  Description 
PointNumber  Point number of the point to retrieve. 
pVal  Returns the specified point. 

At this point I'm totally confused!

thanks
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: debug error ( paremeter is incorrect )
« Reply #1 on: October 16, 2006, 02:22:33 PM »
The "locals" dialog contains this;
Quote
  : oPoint : Nothing : AeccPoint
TheSwamp.org  (serving the CAD community since 2003)

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: debug error ( paremeter is incorrect )
« Reply #2 on: October 16, 2006, 02:47:34 PM »
You just need to know that the Find method throws an error if the point does not exist and plqan for it. Here's a snip from my PackPoints macro that does just that:
Code: [Select]
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
Now, I know some would prefer the error be sent to an error handler, but in this case I just wanted it handled in-line since it is the only possible error that can be raised in this section of code.

Dinosaur

  • Guest
Re: debug error ( paremeter is incorrect )
« Reply #3 on: October 16, 2006, 02:54:33 PM »
Mark, You may want to check out the inquiry too provided with Civil 3D before you invest nuch time on this unless you want the learning experience.  I had a screen shot attached, but it is way to big - a VERY nifty tool!

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: debug error ( paremeter is incorrect )
« Reply #4 on: October 16, 2006, 03:02:16 PM »
You just need to know that the Find method throws an error if the point does not exist and plqan for it. Here's a snip from my PackPoints macro that does just that:

thanks Jeff.
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: debug error ( paremeter is incorrect )
« Reply #5 on: October 16, 2006, 03:10:11 PM »
Mark, You may want to check out the inquiry too provided with Civil 3D before you invest nuch time on this unless you want the learning experience.  I had a screen shot attached, but it is way to big - a VERY nifty tool!

Actually that's why I'm writing this app! :lol:  J/K

I did try it out but it's way to slow for my taste, to much *clickidy click* for me. :-)

I just really want to learn VBA, that's why I'm writing this app.

thanks Steve.
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: debug error ( paremeter is incorrect )
« Reply #6 on: October 16, 2006, 03:21:41 PM »
Looking at some sample code and the docs it appears they want you to use the "ContainsPoint Method" in the "AeccPointGroup".

Quote
Returns true if the group contains the point identified by the specified point number.
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: debug error ( paremeter is incorrect )
« Reply #7 on: October 16, 2006, 03:49:18 PM »
This works;

Code: [Select]
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
TheSwamp.org  (serving the CAD community since 2003)

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: debug error ( paremeter is incorrect )
« Reply #8 on: October 16, 2006, 04:15:09 PM »
While that is certainly one use for that method it seems, to me, to be a time consuming diversion if you are not working with the groups in the first place. (Which if you are just inversing between points you wouldn't be.)

Just determining if the Find(pt) throws an error, or not, does the same thing without accessing the groups/group. And since you need to use the Find(pt) anyway to access the Point's properties.......

Troy Williams

  • Guest
Re: debug error ( paremeter is incorrect )
« Reply #9 on: October 16, 2006, 05:49:38 PM »
Mark,
Would something like this work for you?


This is an example of an error handler that I typically use:
Code: [Select]
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

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: debug error ( paremeter is incorrect )
« Reply #10 on: October 17, 2006, 08:02:03 AM »
Just determining if the Find(pt) throws an error, or not, does the same thing without accessing the groups/group. And since you need to use the Find(pt) anyway to access the Point's properties.......

Can't argue with that. I'm just having a hard time understanding your code. I'm very much a newbie. :-)

thanks again Jeff
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: debug error ( paremeter is incorrect )
« Reply #11 on: October 17, 2006, 08:05:36 AM »
Mark,
Would something like this work for you?
This is an example of an error handler that I typically use:

Thanks Troy, I'm sure it works great, once I understand the code I'm sure I'll appreciate it even more. :-)
TheSwamp.org  (serving the CAD community since 2003)

Troy Williams

  • Guest
Re: debug error ( paremeter is incorrect )
« Reply #12 on: October 17, 2006, 12:36:30 PM »
Mark,
Would something like this work for you?
This is an example of an error handler that I typically use:

Thanks Troy, I'm sure it works great, once I understand the code I'm sure I'll appreciate it even more. :-)


Code: [Select]
On Error Goto ErrorHandler
This line is the key. It tells the compiler what to do when an error occurs. In this case it tells the compiler to go to the label "ErrorHandler" i.e. program execution continues on the line immediately following the label. It is similar to the statement "On Error Resume Next" which tells the complier that if an error occurs skip to the next line after where the error occured.

Keep in mind a label should not be used under normal circumstances as it can lead to code that is difficult to maintain. However, I have found them extremely useful for handling errors as I can group all of the error handling code in one location instead of having it strewn about the rest of the routine.

This next bit of code is the heart of the error handler. It consists of two pieces, the part that allows the program to clean up after itself (close DB connections, dispose of objects, etc.).
Code: [Select]
ExitHere:
'clean up any references...
set oPoint = nothing


exit function
In the "ExitHere" section you will place code that you want to run to make sure that routine exits properly. In the normal course of things, your program would natural flow into the "ExitHere" section and end gracefully. There might be situations where you need to terminate your application early, but you still want to make sure everything is cleaned up.

So instead of using somthing like this:
Code: [Select]
if oPoint is nothing then exit function

You could use something like:
Code: [Select]
if oPoint is nothing then goto ExitHere




The last part of the routine is invoked when an error occurs:
Code: [Select]
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... " & err.number
end select

resume ExitHere
end function
When an error occurs, the "On Error Goto ErrorHandler" is followed and the program continues execution on the line immediately following the "ErrorHandler" label. In this case, the select statement. What your interested in is trapping the error generated by the find method. That is why I have "case -2222" I don't know what error number is thrown. Instead of -2222 you would put the error number that is generated. The next line "resume next" tells the program to jump back up to the line immediately after the line that through the error.

Does that make sense? If you need a better explaination let me know and I'll see what I can whip up tonight.


Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: debug error ( paremeter is incorrect )
« Reply #13 on: October 17, 2006, 12:49:25 PM »
Quote from: Troy
Does that make sense?

Yes it does, thank you very much!
TheSwamp.org  (serving the CAD community since 2003)