×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

run-time error '13'

run-time error '13'

run-time error '13'

(OP)
I'm getting a run-time error '13' when running through a For Each/Next loop.  What is a run-time '13' error and how can I avoid it?

RE: run-time error '13'

I generally don't pay much attention to error numbers, preferring the description instead.

If you could post the error description, and the offending code, it might be helpful.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein

RE: run-time error '13'

(OP)
Below is the section of code that's crashing.

For i = 1 To 5
    If i = 1 Then Name = "MESA2_UX1100"
    If i = 2 Then Name = "MESA3_UX1400"
    If i = 3 Then Name = "MESA4_UX1500"
    If i = 4 Then Name = "MESA5_UX1600"
    If i = 5 Then Name = "MESA6_UX1700"
    varCodeValues(0) = Name
    Call SelectAll
    MsgBox Name & " = " & objSS.Count
        For Each LineObj In ThisDrawing.ActiveSelectionSet
            stPoint = LineObj.StartPoint
            endPoint = LineObj.endPoint
        Next

When the program crashes, it has the last NEXT highlighted and the error code and "Type mismatch".  Even if I take out everything in the For Each loop, I still get the error. The message box shows that I have many lines in the selection set (it's AutoCAD VBA), but I can't get through the For Each loop.

RE: run-time error '13'

What type is a LineObj and does that object type exist within a ThisDCrawing.ActiveSelectionSet object?

Although not necessary, I would also suggest that for code readability, you explicitly identify what the 'next' refers to.

CODE

For i = 1 to 5
   ...
   For Each LineObj in ThisDrawing.ActiveSelectionSet
      ...
   Next LineObj
Next i


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein

RE: run-time error '13'

(OP)
Thanks for the code readability suggestion.

Yes the LineObj is viable.  I put the message box right in front of the For Each statement to determine how many LineObj's were in the selection set.  There is nothing else but LineObj's on that layer, so I know the number in the selection set is the number of LineObj's.

RE: run-time error '13'

What type is LineObj?  How have you dimensioned it?
What type is ThisDrawing?  How has it been dimensioned?

Additionally, but a long shot, how are stPoint and endPoint declared, and are they of the same type as the corresponding LineObj properties?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein

RE: run-time error '13'

(OP)
Dim stPoint As Variant
Dim endPoint As Variant
Dim LineObj As AcadLine

I didn't dimension ThisDrawing since it is the reference to the current document.  I have used these objects many times before in this same program and they work.  I have used the same For Each loops with the same objects and it works.  That's why it's so confusing on this particular one. It works on another file so it must be something related to the file I'm trying to extract the data from.

RE: run-time error '13'

At this point I would look to version incompatibility at the document level.  I am guessing we're dealing with AutoCad? here, and is it possible that the version of AutoCad used to create the document in which this program fails is different from the version of AutoCad that you normally use, or the version that your program is expecting.  It doesn't fail in other documents because different version of AutoCad are not in play.

For example, it may be that the program is expecting a LineObj as defined in AutoCad 2005, but the document was created using AutoCad 2004 so the definition of the LineObj object is different.  That could result in a type mismatch error.

This could be caused by an early binding to the LineObj type (dim LineObj as AcadLine) but a late binding (not dimensioned) to the ThisDrawing object resulting in two different AutoCad object definitions.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein

RE: run-time error '13'

This is unrelated to the error, but all those 'if's are pretty processor hogging.  CASE is usually a more elegant solution for a selection.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources