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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.