Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.access.modulescoding,microsoft.public.excel.programming,microsoft.public.word.programming,microsoft.public.word.vba.general
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.




  #2   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

Thank you David, I've got it now.

Petr


"david" píše v diskusním příspěvku
...
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.






Reply
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 Per Jessen Excel Programming 1 June 11th 09 12:24 PM
Arrays/Redim/Help! LarryP Excel Programming 2 June 2nd 08 06:04 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 08:26 AM.

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

About Us

"It's about Microsoft Excel"