|
-
Oct 28th, 2005, 07:32 AM
#1
Thread Starter
New Member
Redim Multidimensional arrays
OK this just won't work.
VB Code:
Public Function Find_Frac(attArr() As Variant, c As Integer)
Dim slashpos
Dim temphouse
Dim slashExist As Boolean
Dim ai
Dim shouse
Dim addFrac
ReDim Preserve attArr(1, UBound(attArr(), 2) + 1)
temphouse = attArr(1, c)
If InStr(temphouse, "/") Then
slashpos = InStr(temphouse, "/")
shouse = Left(temphouse, slashpos - 3)
attArr(1, c) = shouse
addFrac = Mid(temphouse, slashpos - 1)
attArr(0, ai) = "FRAC"
attArr(1, ai) = addFrac
End If
End Function
When I try to redim attArr() is says it is out of range.
Is this because the array was passed to it?
Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
Last edited by Hack; Oct 28th, 2005 at 07:36 AM.
-
Oct 28th, 2005, 07:48 AM
#2
Re: Redim Multidimensional arrays
Did you step through the code
and added a watch for attArr()?
do you really need a variant array or will a varaint containing an array do to?
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Oct 28th, 2005, 08:00 AM
#3
Thread Starter
New Member
Re: Redim Multidimensional arrays
When I step through the code ReDim Preserve attArr(1, UBound(attArr(), 2) + 1) gets the value of <subscript out of range>.
The array gets used for many different data types of multiple lengths thats the reason for the redim. By all rights this should work. I am just thinking it is because I am passing the array. I have searched and can't find anything where the array wa passed to a function before trying to change the dimension.
-
Oct 28th, 2005, 08:09 AM
#4
Re: Redim Multidimensional arrays
why pass it to the function?
if you need to redim the actual array thats being passed in..
just make the Array global... dont pass it in...
or maybe try rediming before you pass it in?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Oct 28th, 2005, 08:35 AM
#5
Re: Redim Multidimensional arrays
Try this:
VB Code:
ReDim Preserve attArr(1, UBound(attArr, 2) + 1)
I think when you try to UBound attArr(), it is expecting an index for the array.
-
Oct 28th, 2005, 08:41 AM
#6
Thread Starter
New Member
Re: Redim Multidimensional arrays
 Originally Posted by Comintern
Try this:
VB Code:
ReDim Preserve attArr(1, UBound(attArr, 2) + 1)
I think when you try to UBound attArr(), it is expecting an index for the array.
Nope, still get the same error. Thanks though.
-
Oct 28th, 2005, 09:36 AM
#7
Re: Redim Multidimensional arrays
The problem is in your passing attempt. not in the manipulating of it....I suspect
retry to add a watch and be sure your cursor is in the recieving function
the error you posted can be an out of scope error for the watch
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Oct 28th, 2005, 10:52 AM
#8
Thread Starter
New Member
Re: Redim Multidimensional arrays
Ok, I went back a little further to a function that fills the array to begin with.
VB Code:
Public Function Get_Attributes(objBlock As AcadBlockReference, arrAttribute() As Variant)
Dim i As Integer
Dim c As Integer
c = UBound(objBlock.GetAttributes)
ReDim arrAttribute(2, c)
'At this point ubound(arrAttibute) = 14
ReDim Preserve arrAttribute(2, c + 1)
' ubound(arrAttibute) = 15
For Each Attrib In objBlock.GetAttributes
arrAttribute(0, i) = Attrib.TagString
arrAttribute(1, i) = Attrib.TextString
i = i + 1
Next
ReDim Preserve arrAttribute(2, c + 1)
'Redim failed ubound(arrAttibute) = 15
End Function
Once the array is populated the redim fails with or without Preserve
-
Oct 28th, 2005, 10:59 AM
#9
Re: Redim Multidimensional arrays
Redim of multidimensional arrays can only change the highest dimension. The latest code you posted has the first dimension as 2, the earlier code tries to redim it to 1.
-
Oct 31st, 2005, 07:48 AM
#10
Re: Redim Multidimensional arrays
Indeed and in case you are wondering why it is because array data is stored sequentially. If you did change the lower dimension it would affect how the data was read into the 2D indices. To do it correctly you would need to move the data row by row to a new array and handle any loss of data.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|