View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
Alan Beban[_2_] Alan Beban[_2_] is offline
external usenet poster
 
Posts: 783
Default redimensioning arrays in subroutines

Les Gordon wrote:
I was wondering what would happen if you declared it as Variant then
redimensioned which would give it a definite array size; the later in the
code redimensioned again to a different array size. Would it behave since it
started life as a variant; or not behave since it now has a definite size and
so act like a declared array.

My appologies if you get two answers to this but the first response seems to
have disappeared in to the ether.

My response was in this thread yesterday, 3/31/08, at 6:26pm. Are you
not finding it? It was

It would be allowed.

Although I find it a bit offputting that after the first ReDim

e.g.,
Dim x
Redim x(10,10,10)

x in a sense refers both to the Variant variable and to the Variant()
array contained within the Variant variable, the Variant variable no
longer seems to be accessible. For example, Typename(x) will return
Variant() and IsArray(x) will return True, each obviously referring to
the array and not to the variable.

You might want to set up a simple experiment and see how things are
characterized in the Locals Window.

E.g.,

Sub testReDim()
Dim x(), y
ReDim x(10, 10, 10)
ReDim y(10, 10, 10)
x(1, 1, 1) = "xok"
y(1, 1, 1) = "yok"
ReDim Preserve x(10, 10, 1 To 11)
ReDim Preserve y(10, 10, 2 To 11)
Stop
End Sub

Alan Beban