• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

using Redim in arrays

if I have an array of 2 dimensions, example:

dim sname(2,1) as string

then I want to preserve existing values and change the number of elements in both dimension. Like Redim sname(3,3). Would this work?

thanks


0
jskfan
Asked:
jskfan
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
No.

You can only change the number of elements in the last dimension.

From the help file:

    "If you use the Preserve keyword, you can resize only the last array dimension and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array. The following example shows how you can increase the size of the last dimension of a dynamic array without erasing any existing data contained in the array.

ReDim X(10, 10, 10)
. . .
ReDim Preserve X(10, 10, 15)

Similarly, when you use Preserve, you can change the size of the array only by changing the upper bound; changing the lower bound causes an error."
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now