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

Hi Joel,

thank you, that works. I got a similar tip from RB, the temp array first,
then put that in the variant array. Works perfectly.

Petr



"Joel" píše v diskusním příspěvku
...
Sub test()
Dim Kde() As Variant
Dim Kde1 As Variant
Dim Kde2 As Variant
'..
'..
Kde1 = Array(0, 198, 0, 180, 1, 47)
Kde2 = Array(0, 1980, 0, 1800, 1, 65)


'and I referenced array elements with the standard syntax of
ReDim Kde(2)
Kde(0) = Kde1
Kde(1) = Kde2
i = Kde(km)(0)
j = Kde(km)(5)


End Sub


"Petr Danes" wrote:

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 arrays in Variant No Name Excel Programming 0 June 11th 09 11:39 AM
ReDim an array of variant - Help doj Excel Programming 1 October 27th 06 11:00 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 07:03 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"