Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

run-time error '13'

Status
Not open for further replies.

jrice174

Civil/Environmental
Nov 8, 2004
129
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?
 
Replies continue below

Recommended for you

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
 
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.
 
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
 
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.
 
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
 
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.
 
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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor