dynamic 2 dimensional array in vb 6

Reply

Join Date: Oct 2007
Posts: 3
Reputation: stargazr is an unknown quantity at this point 
Solved Threads: 0
stargazr stargazr is offline Offline
Newbie Poster

dynamic 2 dimensional array in vb 6

 
0
  #1
Oct 8th, 2007
how to declare dynamic 2 dimensional array in vb with one of the bounds variable ..
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. dim x(1 to i,1 to 4) as variant
  2. 'i is a variable
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 20
Reputation: shasur is an unknown quantity at this point 
Solved Threads: 1
shasur shasur is offline Offline
Newbie Poster

Re: dynamic 2 dimensional array in vb 6

 
0
  #2
Oct 8th, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC