Simple Question on VBA AutoCAD arrays.
Simple Question on VBA AutoCAD arrays.
(OP)
I am trying to use A dynamic array in VBA and I am having a problem. I wrote the following function to Redim my Dynamic array and add an element to the last spot.
Function DarrayAdd(Darray As Variant, Ditem As Variant)
ReDim Preserve Darray(UBound(Darray) + 1)
Darray(UBound(Darray)) = Ditem
End Function
Real Simple Huh? The problem is that Ubound returns Error 9 "Subscript out of Range" when I run this. I can declare the initial array with a value of 1 and then Ubound works but I get a message telling me the array is locked or in use. If I pass the Array by value (Byval Darray as Variant.. I can work with it, but it doesn't affect the initial array and the Gymnastics I would have to do to pass it back make this not worthwhile. Does anyone have any idea what I am doing wrong? Basically I need a quick and easy way to expand my array by 1 and add an item to that spot.
Function DarrayAdd(Darray As Variant, Ditem As Variant)
ReDim Preserve Darray(UBound(Darray) + 1)
Darray(UBound(Darray)) = Ditem
End Function
Real Simple Huh? The problem is that Ubound returns Error 9 "Subscript out of Range" when I run this. I can declare the initial array with a value of 1 and then Ubound works but I get a message telling me the array is locked or in use. If I pass the Array by value (Byval Darray as Variant.. I can work with it, but it doesn't affect the initial array and the Gymnastics I would have to do to pass it back make this not worthwhile. Does anyone have any idea what I am doing wrong? Basically I need a quick and easy way to expand my array by 1 and add an item to that spot.





RE: Simple Question on VBA AutoCAD arrays.
At this point you need to declare the array with a Dim statement - e.g. Dim MyArray().
After you have done this, enter the first value explicitly -
e.g.
ReDim MyArray(1 to 1)
MyArray(1)=3.245
Thereafter you can use the ReDim Preserve statement safely.
Good luck...
Mala Singh
'Dare to Imagine'
RE: Simple Question on VBA AutoCAD arrays.
RE: Simple Question on VBA AutoCAD arrays.
Mala Singh
'Dare to Imagine'
RE: Simple Question on VBA AutoCAD arrays.
I am not good at languages other than English - but I suspect 'LumpoDelMagnifico' is Spanish?
Can you translate this for me? I just want to verify if it really means what I suspect it is meant to mean...I am not divulging my guess lest someone red-flags this post!!
Mala Singh
'Dare to Imagine'
RE: Simple Question on VBA AutoCAD arrays.
AddItem MyStringArray, "LumpyRox"
or
AddItem MyIntArray, 1
But I think I was just overreaching
RE: Simple Question on VBA AutoCAD arrays.
RE: Simple Question on VBA AutoCAD arrays.
Fortunately, the meaning is not half as bad as I had imagined...
Mala Singh
'Dare to Imagine'