View Single Post
  #1   Report Post  
Posted to microsoft.public.access.modulescoding,microsoft.public.excel.programming,microsoft.public.word.programming,microsoft.public.word.vba.general
david[_11_] david[_11_] is offline
external usenet poster
 
Posts: 1
Default ReDim arrays in Variant

Public Sub myredim(v As Variant, x)
ReDim Preserve v(x)
End Sub

....

Dim Kde As Variant
ReDim Kde(2)
Kde(1) = Array(Null, 198, 0, 180, 1, 47)
Kde(2) = Array(0, 1980, 0, 1800, 1, 65)

ReDim Kde(3)
Kde(3) = Array(1)

myredim(Kde(2),6)
Kde(2)(6) = 7

(david)


"Petr Danes" wrote in message
...
I have a syntax issue with VBA. It happens that I'm doing this in Access,
but the question applies to VBA all across the Office package, so I'm
posting this to several VBA-related groups, since it may also be of
interest to programmers in applications other than Access.

I have a variant which contains several one-dimensional arrays. I load
each array with some stuff I read out of the TAG property of a page,
specific to that page, so that the code will be able to handle an
arbitrary number of pages. I anticipate some growth, and coding it this
way allows me to simply add a new page, with the appropriate parameters in
the TAG property and my app will continue to function, without the
necessity for altering the actual code.

Fine so far, all this works well. My initial code was as follows:

Dim Kde(2)
.
.
Set Kde(1) = Array(0, 198, 0, 180, 1, 47)
Set Kde(2) = Array(0, 1980, 0, 1800, 1, 65)

and I referenced array elements with the standard syntax of

i = Kde(km)(0)
j = Kde(km)(5)

and so on.

What I want to do now is dim the variant without parameters,

Dim Kde()

and use ReDim to dynamically allocate BOTH the number of elements in the
Kde variant AND the number of elements in the individual arrays in the Kde
variant (not at the same time). As I scan for pages that interest me, I
want to use ReDim to add new elements to Kde when I find a page I like,
then look at the TAG property, count the parameters stored there and ReDim
the array in that newly added element of Kde to the proper number of
elements before loading the parameters.

As it is, I have to change the code to modify the number of elements when
I add a page. Using the ReDim would make the code completely modular,
adding a page would not then require ANY coding modifications. Does anyone
know the syntax for this? Is it even possible? The online help seems to
indicate that it can be done:

"Note To resize an array contained in a Variant, you must explicitly
declare the Variant variable before attempting to resize its array."

Conceptually, it also seems doable, but all my experiments with this have
yielded only syntax errors.

Petr



--
This e-mail address is fake, to keep spammers and their address harvesters
out of my hair. If you need to get in touch personally, I am 'pdanes' and
I use yahoo mail. But please use the newsgroups whenever possible, so that
all may benefit from the exchange of ideas.