<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to have variable array variable? in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/how-to-have-variable-array-variable/m-p/2372028#M17440</link>
    <description>Ok, ok, so my naming convention needs to be a bit less&lt;BR /&gt;
linear. ;^)&lt;BR /&gt;
&lt;BR /&gt;
I ran a test after adding the redim statements just to make &lt;BR /&gt;
sure I did it right. Lo and behold, not only did it work but&lt;BR /&gt;
without even having the sort routine in there it drew the &lt;BR /&gt;
correctly. (well except for closing the polyline) &lt;BR /&gt;
&lt;BR /&gt;
I did a number of tests on a lot of different boundaries with&lt;BR /&gt;
anywhere from 40 points to &amp;gt;500 points. They all came out&lt;BR /&gt;
great.&lt;BR /&gt;
&lt;BR /&gt;
The only reason the line doesn't close is because the previous&lt;BR /&gt;
line&lt;BR /&gt;
&lt;BR /&gt;
Set PLineObj = ThisDrawing.ModelSpace.AddPolyline(GetCoord)&lt;BR /&gt;
&lt;BR /&gt;
bombs out on a Type mismatch error. I'll figure that out myself.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt;but im sure we'll be seeing you back here soon &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;
Are you saying I have too many questions? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Believe me, I use this great forum as a last resort when all my&lt;BR /&gt;
own experimenting fails.&lt;BR /&gt;
&lt;BR /&gt;
bc</description>
    <pubDate>Thu, 30 Oct 2008 17:44:16 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2008-10-30T17:44:16Z</dc:date>
    <item>
      <title>How to have variable array variable?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-have-variable-array-variable/m-p/2372026#M17438</link>
      <description>&lt;P&gt;
As the code below shows I am trying to use an array with&lt;BR /&gt;
a variable subscript. I have the dynamic array GetPoint() into &lt;BR /&gt;
which I want to put an unknown number of points. 
&lt;/P&gt;
&lt;P&gt;
When trying to assign a value to GetPoint(x) I keep getting the &lt;BR /&gt;
message: 
&lt;/P&gt;
&lt;P&gt;
Subscript out of range 
&lt;/P&gt;
&lt;P&gt;
because the code doesn't like variable subscripts, ie, GetPoint(x). 
&lt;/P&gt;
&lt;P&gt;
Is there a way to do this? 
&lt;/P&gt;
&lt;P&gt;
The idea behind the code is to select on screen all points needed &lt;BR /&gt;
for a boundary, have the code sort the points based on the Handle&lt;BR /&gt;
property of the points then draw a polyline (or 3dPolyline) connecting&lt;BR /&gt;
all the boundary points. 
&lt;/P&gt;
&lt;P&gt;
This assumes the points are first acquired in the proper order for a &lt;BR /&gt;
boundary, then paste the coordinates in x,y,z format (from an Excel&lt;BR /&gt;
spreadsheet) onto the command line using the 
&lt;/P&gt;
&lt;P&gt;
Draw/Point/Multiple point 
&lt;/P&gt;
&lt;P&gt;
command. This will give each point a sequential numbered handle. But&lt;BR /&gt;
when selecting points en masse on screen the order is all jumbled up, &lt;BR /&gt;
hence the need to sort. 
&lt;/P&gt;
&lt;P&gt;
bc 
&lt;/P&gt;
&lt;P&gt;
&lt;BR /&gt;
Sub DrawBoundary() 
&lt;/P&gt;
&lt;P&gt;
Dim Points() As Double&lt;BR /&gt;
Dim LineObj As AcadPolyline&lt;BR /&gt;
Dim PLineObj As Acad3DPolyline&lt;BR /&gt;
Dim ssetObj1 As AcadSelectionSet&lt;BR /&gt;
Dim cnt As Integer&lt;BR /&gt;
Dim c As Integer&lt;BR /&gt;
Dim x As Integer&lt;BR /&gt;
Dim GetPoint() As Variant&lt;BR /&gt;
Dim GetCoord() As Variant&lt;BR /&gt;
Dim Point As AcadPoint 
&lt;/P&gt;
&lt;P&gt;
On Error Resume Next&lt;BR /&gt;
ThisDrawing.SelectionSets.Item("Points").Delete&lt;BR /&gt;
On Error GoTo 0&lt;BR /&gt;
&lt;BR /&gt;
Set ssetObj1 = ThisDrawing.SelectionSets.Add("Points")&lt;BR /&gt;
&lt;BR /&gt;
Dim intCode(1) As Integer&lt;BR /&gt;
Dim varData(1) As Variant&lt;BR /&gt;
intCode(0) = 0: varData(0) = "POINT" 'this is type of object looked for&lt;BR /&gt;
intCode(1) = 8: varData(1) = "Points" 'this is layer object is on&lt;BR /&gt;
&lt;BR /&gt;
ThisDrawing.Utility.Prompt "Select on screen all boundary points:"&lt;BR /&gt;
ssetObj1.SelectOnScreen intCode, varData&lt;BR /&gt;
cnt = ssetObj1.Count&lt;BR /&gt;
&lt;BR /&gt;
x = 0: c = 0&lt;BR /&gt;
For Each Point In ssetObj1&lt;BR /&gt;
GetPoint(x) = Point.Handle&lt;BR /&gt;
GetCoord(c) = Point.Coordinates(0)&lt;BR /&gt;
GetCoord(c + 1) = Point.Coordinates(1)&lt;BR /&gt;
GetCoord(c + 2) = Point.Coordinates(2)&lt;BR /&gt;
x = x + 1: c = c + 3&lt;BR /&gt;
Next 
&lt;/P&gt;
&lt;P&gt;
'sort routine will eventually go here&lt;BR /&gt;
'&lt;BR /&gt;
'&lt;BR /&gt;
'assign sorted points to Points() here&lt;BR /&gt;
'&lt;BR /&gt;
' &lt;BR /&gt;
' Create a lightweight Polyline object in model space&lt;BR /&gt;
Set LineObj = ThisDrawing.ModelSpace.AddPolyline(Points) 
&lt;/P&gt;
&lt;P&gt;
LineObj.Closed = True&lt;BR /&gt;
&lt;BR /&gt;
End Sub 
&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2008 14:52:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-have-variable-array-variable/m-p/2372026#M17438</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-10-30T14:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to have variable array variable?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-have-variable-array-variable/m-p/2372027#M17439</link>
      <description>Well, I would have set the job up so it was a bit less confusing. You have a selection set named "Points", looking for Points, on a layer called points? Then you are trying to store the data in an array called Points? while looping thru objects named "Point" &lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;
..... get the point?&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;
You declared your array, but never told VB what size it was to be. You can dim an array up front "Dim MyArray(5) as Double"&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;
.. you can erase/resize it afterwards "ReDim MyArray(7) as Double".. you can even dim it empty at the start, and then, somewhere down the line, add/change the size dyanamically "ReDim Preserve MyArray(MyCounter) as Double" and keep all the stuff inside....&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
But somewhere along the line, you have to put in a hard number, or a variable, or *something* that lets VB know how much "stuff" it has to store .. at least until you tell it some other size, in your next pass thru your loop  &lt;GRIN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Since your "getPoint" array is a string (Handle), Id dim it up front as such:&lt;BR /&gt;&lt;BR /&gt;
Dim GetPoint() As String&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
And Similary, Dim your 'GetCoord" array as Double:&lt;BR /&gt;&lt;BR /&gt;
Dim GetCoord() As Double&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
Now, once you get the number of items you are looping thru, in the "cnt" property of the selection set, REDIM the array to the proper&lt;BR /&gt;
size, before you run thru the loop. (Remembering that a COUNT property is 1-based, and arrays are 0-based:&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
redim GetPoint(cnt-1)&lt;BR /&gt;&lt;BR /&gt;
redim GetCoord((cnt*3)-1)&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thats all for now, my lunch is almost over - but im sure we'll be seeing you back here soon  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
eclared an array of variants, and not a variant array. If that makes your head hurt, then do what I do and stick to doubles&lt;/GRIN&gt;</description>
      <pubDate>Thu, 30 Oct 2008 16:43:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-have-variable-array-variable/m-p/2372027#M17439</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-10-30T16:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to have variable array variable?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-have-variable-array-variable/m-p/2372028#M17440</link>
      <description>Ok, ok, so my naming convention needs to be a bit less&lt;BR /&gt;
linear. ;^)&lt;BR /&gt;
&lt;BR /&gt;
I ran a test after adding the redim statements just to make &lt;BR /&gt;
sure I did it right. Lo and behold, not only did it work but&lt;BR /&gt;
without even having the sort routine in there it drew the &lt;BR /&gt;
correctly. (well except for closing the polyline) &lt;BR /&gt;
&lt;BR /&gt;
I did a number of tests on a lot of different boundaries with&lt;BR /&gt;
anywhere from 40 points to &amp;gt;500 points. They all came out&lt;BR /&gt;
great.&lt;BR /&gt;
&lt;BR /&gt;
The only reason the line doesn't close is because the previous&lt;BR /&gt;
line&lt;BR /&gt;
&lt;BR /&gt;
Set PLineObj = ThisDrawing.ModelSpace.AddPolyline(GetCoord)&lt;BR /&gt;
&lt;BR /&gt;
bombs out on a Type mismatch error. I'll figure that out myself.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt;but im sure we'll be seeing you back here soon &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;
Are you saying I have too many questions? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Believe me, I use this great forum as a last resort when all my&lt;BR /&gt;
own experimenting fails.&lt;BR /&gt;
&lt;BR /&gt;
bc</description>
      <pubDate>Thu, 30 Oct 2008 17:44:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-have-variable-array-variable/m-p/2372028#M17440</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-10-30T17:44:16Z</dc:date>
    </item>
  </channel>
</rss>

