954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

dynamic 2 dimensional array in vb 6

how to declare dynamic 2 dimensional array in vb with one of the bounds variable ..

dim x(1 to i,1 to 4) as variant
'i is a variable
stargazr
Newbie Poster
3 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

You can do that by Redim statement


Sub Array_Dimensioning()
Dim arTemp() As Integer ' Preserved Array
Dim arTemp1() As Integer ' Array without Preserve
ReDim Preserve arTemp(1, 1)
ReDim arTemp1(1, 1)
arTemp(1, 1) = 1
ReDim Preserve arTemp(1, 2)
arTemp(1, 2) = 2
ReDim Preserve arTemp(1, 3)
arTemp(1, 3) = 3
ReDim Preserve arTemp(2, 3)
ReDim arTemp1(2, 1)
End Sub

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 arTemp falls under this category. However, arTemp1 you can redimension the array in any dimension, but the contents will be erased with every Redim statement

shasur
Newbie Poster
20 posts since Aug 2006
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You