R
Rhino
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?
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?