Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

Choosing one of several arrays?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed - 02 May 2006 23:57 GMT
I have strings belonging to different series - A, B, C, and D - that I want
to write to a corresponding array - aryA(), aryB(), aryC(), or aryD().  I
will ReDim each array before I write the next string using a variable "x" to
represent the next number.  What is the right way to refer to the correct
array?  I've tried the following with no luck
-- Assign a variable (such as "Y") to the correct series and use
ReDim ary & Y(x)
-- Assign a variable to whole array name and use
ReDim Y(x)
-- Assign a variable to whole array name and use
ReDim Array("Y")(x)

Any help?
Ed
Jezebel - 03 May 2006 09:12 GMT
You can't do any tricks with variable names. In the compiled code -- which
is what actually runs -- there are no variable names at all; only pointers.

Two workarounds that might suit (depending on what else is going on in your
code) --

1) Use an array of arrays:

Dim pData(1 to 4)    as variant

Dim aryA() as string
Dim aryB() as string

pData(1) = aryA
pData(2) = aryB

It's maybe a little obfuscated, but you can refer to aryA(3)  using
pData(1)(3)

2) Use a collection:

Dim pCollection as collection
Dim aryA() as string
Dim aryB() as string

set pCollection = new collection
pCollection.Add Item:=aryA, Key:="Array_A"

>I have strings belonging to different series - A, B, C, and D - that I want
>to write to a corresponding array - aryA(), aryB(), aryC(), or aryD().  I
[quoted text clipped - 10 lines]
> Any help?
> Ed
Ed - 03 May 2006 14:36 GMT
Thanks, Jezebel.  Thinking a bit more, I wonder if it's possible and, if so,
maybe easier to use a two-dimensional array and use a variable to decide
where I'm writing.  For instance, if I have six series of data, can I write
to MyAry(x, y), where "x" is assigned to 1-6 according to which series I
assign my data to?

Also, if I use ReDim Preserve with this, I know I can only resize "y".  Is
"y" then the total number of elements across the whole complete array, or
just that section of the array?  Or do I ReDim to the highest number of
elements in any single section?  If in MyAry(1,y) y=4 and in MyAry(2,y) y=6,
if I wanted to add another item to MyAry(1,y+1) would I have to ReDim to 5,
or to 11, or not have to ReDim at all because MyAry(2,y) has 6 items, more
than the 5 the first section will have?  (Did that make sense??)

Ed

> You can't do any tricks with variable names. In the compiled code -- which
> is what actually runs -- there are no variable names at all; only
[quoted text clipped - 39 lines]
>> Any help?
>> Ed
Jezebel - 04 May 2006 05:14 GMT
Yes you can use a two-dimensional (or indeed any dimensional) array; but the
dimensions are constant (think of the array as representing a rectangle  -
or cube or whatever - of cells). So you'd have to set it up for the second
dimension to accommodate the largest set of values you might need.

> Thanks, Jezebel.  Thinking a bit more, I wonder if it's possible and, if
> so, maybe easier to use a two-dimensional array and use a variable to
[quoted text clipped - 56 lines]
>>> Any help?
>>> Ed
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.