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 / January 2006

Tip: Looking for answers? Try searching our database.

Dynamic Arrays question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rhino - 27 Jan 2006 15:38 GMT
I am trying to write a VBA macro in Word and need some guidance on how to
use a dynamic array.

One part of my macro needs to read in a long semicolon-delimited string that
is on a single line of an external text file. I will use Split() to slice it
up into an array of one dimension and I already have that working.

I want to take my one dimensional array and write its data into a two
dimensional array. I know that the second dimension of the array will be 5,
but I want to calculate the first dimension. The first dimension of the
two-dimensional array will be the number of elements in the one-dimensional
array divided by 5.

Assuming that the size of the one-dimensional array is in an integer
variable called sizeArray1D and that there is an integer const named FIVE
with the value 5,  I tried to create the two-dimensional array like this:

   dim Array2D as String(sizeArray1D/FIVE, FIVE)

However, VB doesn't like this at all and only accepts constants as the array
dimensions.

So, I decided to create the array as a dynamic array and used this to define
the array:

   dim Array2D as String

VB doesn't object to this statement but as soon as I try to assign a value
to the array via this statement:

   Array2D(0, 0) = Array1D(0)

it complains about an out-of-range subscript. Since all of the subscripts
are zero and I haven't changed the lower bounds of any array to be anything
other than zero, I assume that this is just masking the real problem.

Have I declared Array2D correctly? I don't see anything in the definition
that makes it a two dimensional array and I haven't done anything later to
make it one either, at least not explicitly. The Help pages don't discuss
the case of making a multi-dimensional dynamic array.

Can anyone tell me how to define a dynamic two-dimensional array so that I
can successfully copy my one dimensional array to my two dimensional array?
Or can dynamic arrays only be one dimensional?

Signature

Rhino

Tony Jollans - 27 Jan 2006 18:04 GMT
Try ..

   dim Array2D as String
   Redim Array2D (sizeArray1D/FIVE, FIVE)

--
Enjoy,
Tony

> I am trying to write a VBA macro in Word and need some guidance on how to
> use a dynamic array.
[quoted text clipped - 43 lines]
> --
> Rhino
Rhino - 27 Jan 2006 18:52 GMT
Thank you, that worked just fine!

Rhino

> Try ..
>
[quoted text clipped - 63 lines]
>> --
>> Rhino
Tony Jollans - 27 Jan 2006 19:38 GMT
My pleasure!

--
Enjoy,
Tony

> Thank you, that worked just fine!
>
[quoted text clipped - 67 lines]
> >> --
> >> Rhino

Rate this thread:






 
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.