Message 1 of 25
why subscript out of range error?

Not applicable
09-17-2008
10:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm having trouble with the following code. In line 10 I get
a 'Subscript out of range' error on intPoints(2). I followed the
IntersectWith code example in the help file but don't see
where mine should operate any different than theirs.
They dimmed intPoints as Variant and so did I. They then extracted
point info from the variable (intPoints(j)) and so did I (intPoints(2)).
Yet I get the error. And the variable LinLen always remains empty.
What am I doing wrong?
bc
Sub Intersect()
'This code is supposed to find the intersection point between
'a line and a 3dFace, check the length of the line stretched
'to that point then find an area based on that length.
Dim msg As String
Dim ssetObj1 As AcadSelectionSet
Dim ssetObj2 As AcadSelectionSet
Set ssetObj1 = ThisDrawing.SelectionSets.Add("TopLines")
Set ssetObj2 = ThisDrawing.SelectionSets.Add("TopFaces")
'the following selections are made en masse, ie not in any particular order
'there are approx. 3600 lines and 16 3dFaces
msg = MsgBox("Select on screen all the TOP lines.", vbOKOnly)
ssetObj1.SelectOnScreen
msg = MsgBox("Select on screen all the TOP faces.", vbOKOnly)
ssetObj2.SelectOnScreen
Dim LinLen As Variant
Dim intPoints As Variant
Dim TopArea As Variant
Dim Area As Variant
Dim entTopLine As AcadLine
Dim entTopFace As Acad3DFace
'each of the 3600 lines are tested for intersection with a 3dFace
For Each entTopLine In ssetObj1
'the 3dFaces are cycled thru to check for intersection with line
For Each entTopFace In ssetObj2
On Error Resume Next
intPoints = entTopLine.IntersectWith(entTopFace, acExtendThisEntity)
10 LinLen = intPoints(2) - 10 'error occurs here
Area = LinLen * 0.25
TopArea = TopArea + Area
Next
Next
ssetObj1.Delete
ssetObj2.Delete
End Sub
a 'Subscript out of range' error on intPoints(2). I followed the
IntersectWith code example in the help file but don't see
where mine should operate any different than theirs.
They dimmed intPoints as Variant and so did I. They then extracted
point info from the variable (intPoints(j)) and so did I (intPoints(2)).
Yet I get the error. And the variable LinLen always remains empty.
What am I doing wrong?
bc
Sub Intersect()
'This code is supposed to find the intersection point between
'a line and a 3dFace, check the length of the line stretched
'to that point then find an area based on that length.
Dim msg As String
Dim ssetObj1 As AcadSelectionSet
Dim ssetObj2 As AcadSelectionSet
Set ssetObj1 = ThisDrawing.SelectionSets.Add("TopLines")
Set ssetObj2 = ThisDrawing.SelectionSets.Add("TopFaces")
'the following selections are made en masse, ie not in any particular order
'there are approx. 3600 lines and 16 3dFaces
msg = MsgBox("Select on screen all the TOP lines.", vbOKOnly)
ssetObj1.SelectOnScreen
msg = MsgBox("Select on screen all the TOP faces.", vbOKOnly)
ssetObj2.SelectOnScreen
Dim LinLen As Variant
Dim intPoints As Variant
Dim TopArea As Variant
Dim Area As Variant
Dim entTopLine As AcadLine
Dim entTopFace As Acad3DFace
'each of the 3600 lines are tested for intersection with a 3dFace
For Each entTopLine In ssetObj1
'the 3dFaces are cycled thru to check for intersection with line
For Each entTopFace In ssetObj2
On Error Resume Next
intPoints = entTopLine.IntersectWith(entTopFace, acExtendThisEntity)
10 LinLen = intPoints(2) - 10 'error occurs here
Area = LinLen * 0.25
TopArea = TopArea + Area
Next
Next
ssetObj1.Delete
ssetObj2.Delete
End Sub