LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.access.modulescoding,microsoft.public.excel.programming,microsoft.public.word.programming,microsoft.public.word.vba.general
No Name
 
Posts: n/a
Default ReDim arrays in Variant

Hello RB,

thank you, that was the way to do it. It didn't occur to me to use a
separate array and then assign it to an element in the variant, I was
trying to ReDim the array already contained in the variant, and there's
probably no syntax to do that directly. Your way works perfectly.

And of course, you're right about the Set. That wasn't a cut and paste from
my code, I retyped it into my post from (obviously faulty) memory. My actual
code has it right, otherwise it would not even have compiled.

Appreciate the help.

Petr



"RB Smissaert" píše v diskusním příspěvku
...
Try something like this:

Sub test()

Dim Kde(1 To 2)
Dim arr

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

MsgBox Kde(1)(UBound(Kde(1)))

arr = Kde(1)

ReDim Preserve arr(0 To 10)

Kde(1) = arr
Kde(1)(10) = 100

MsgBox Kde(1)(10)

End Sub


Note that you don't want to use Set as you did as that is for objects.


RBS


"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.





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ReDim arrays in Variant david[_11_] Excel Programming 1 June 11th 09 12:40 PM
ReDim arrays in Variant Per Jessen Excel Programming 1 June 11th 09 12:24 PM
ReDim an array of variant - Help doj Excel Programming 1 October 27th 06 11:00 PM
ReDim Variant array for worksheet copy John Keith[_2_] Excel Programming 1 February 16th 06 09:52 PM
how to redim the type of variant element lvcha.gouqizi Excel Programming 5 October 25th 05 07:05 PM


All times are GMT +1. The time now is 06:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright Š2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"