How to have variable array variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
As the code below shows I am trying to use an array with
a variable subscript. I have the dynamic array GetPoint() into
which I want to put an unknown number of points.
When trying to assign a value to GetPoint(x) I keep getting the
message:
Subscript out of range
because the code doesn't like variable subscripts, ie, GetPoint(x).
Is there a way to do this?
The idea behind the code is to select on screen all points needed
for a boundary, have the code sort the points based on the Handle
property of the points then draw a polyline (or 3dPolyline) connecting
all the boundary points.
This assumes the points are first acquired in the proper order for a
boundary, then paste the coordinates in x,y,z format (from an Excel
spreadsheet) onto the command line using the
Draw/Point/Multiple point
command. This will give each point a sequential numbered handle. But
when selecting points en masse on screen the order is all jumbled up,
hence the need to sort.
bc
Sub DrawBoundary()
Dim Points() As Double
Dim LineObj As AcadPolyline
Dim PLineObj As Acad3DPolyline
Dim ssetObj1 As AcadSelectionSet
Dim cnt As Integer
Dim c As Integer
Dim x As Integer
Dim GetPoint() As Variant
Dim GetCoord() As Variant
Dim Point As AcadPoint
On Error Resume Next
ThisDrawing.SelectionSets.Item("Points").Delete
On Error GoTo 0
Set ssetObj1 = ThisDrawing.SelectionSets.Add("Points")
Dim intCode(1) As Integer
Dim varData(1) As Variant
intCode(0) = 0: varData(0) = "POINT" 'this is type of object looked for
intCode(1) = 8: varData(1) = "Points" 'this is layer object is on
ThisDrawing.Utility.Prompt "Select on screen all boundary points:"
ssetObj1.SelectOnScreen intCode, varData
cnt = ssetObj1.Count
x = 0: c = 0
For Each Point In ssetObj1
GetPoint(x) = Point.Handle
GetCoord(c) = Point.Coordinates(0)
GetCoord(c + 1) = Point.Coordinates(1)
GetCoord(c + 2) = Point.Coordinates(2)
x = x + 1: c = c + 3
Next
'sort routine will eventually go here
'
'
'assign sorted points to Points() here
'
'
' Create a lightweight Polyline object in model space
Set LineObj = ThisDrawing.ModelSpace.AddPolyline(Points)
LineObj.Closed = True
End Sub