|
Prev: VB6 IDE right-click module remove
Next: Hate Your Job?
From: George Hester on 29 Jun 2008 05:06 I would like to access just one dimension of a multi-column and rows array. Something like if A(i,j) is an array with values for i and j how about A(I,j) being just a one-dimensional array? I could be say the number of elements i. Thanks. -- George Hester _________________________________
From: RB Smissaert on 29 Jun 2008 05:18 I don't think there is any simple way to do that other than making a new array and copying from the old to the new array, so something like this: Dim i As Long Dim A(0 To 10, 0 To 2) As Long Dim A1() As Long ReDim A1(LBound(A) To UBound(A)) As Long For i = LBound(A1) To UBound(A1) A1(i) = A(i, 1) Next i RBS "George Hester" <hesterloli(a)hotmail.com> wrote in message news:%23FX6zdc2IHA.3600(a)TK2MSFTNGP04.phx.gbl... >I would like to access just one dimension of a multi-column and rows array. > Something like if A(i,j) is an array with values for i and j how about > A(I,j) being just a one-dimensional array? I could be say the number of > elements i. Thanks. > > -- > > George Hester > _________________________________ > >
From: Larry Serflaten on 29 Jun 2008 08:46 "George Hester" <hesterloli(a)hotmail.com> wrote > I would like to access just one dimension of a multi-column and rows array. > Something like if A(i,j) is an array with values for i and j how about > A(I,j) being just a one-dimensional array? I could be say the number of > elements i. Thanks. Not gonna happen, unless you build it as an array of arrays. Even then it may not be worth the hassle since you can just pass a reference to the entire mutli-dim. array around and iterate through whatever you need. LFS Private Sub Form_Load() Dim row(0 To 3), col, i For i = 0 To 3 ' Populating an array of arrays.... ReDim col(0 To 2) As Long col(0) = i col(1) = i + i col(2) = i + i + i row(i) = col Next i col = row(2) ' Grab that one row... For i = 0 To 2 Debug.Print i, col(i) Next End Sub
From: Jim Mack on 29 Jun 2008 11:39 George Hester wrote: > I would like to access just one dimension of a multi-column and > rows array. Something like if A(i,j) is an array with values for i > and j how about A(I,j) being just a one-dimensional array? I could > be say the number of elements i. Thanks. VB doesn't natively allow that, but it's possible to fool VB into thinking it does, depending on how the array is ordered. But it's a hack, and has to be approached carefully. Basically, the idea is to create a blank single-dim array, and manipulate its SafeArray structure to have the correct bounds, and a pointer to the data of interest. It's not for the inexperienced or the careless, though. You can get things bollixed up pretty well if you miss a step, or do something you shouldn't. -- Jim Mack MicroDexterity Inc www.microdexterity.com
From: George Hester on 29 Jun 2008 17:27
That sounds neat. A 1-dim array of pointers to the second column of the multi-dim array A Interesting. Thanks for the tip. -- George Hester _________________________________ "Jim Mack" <jmack(a)mdxi.nospam.com> wrote in message news:eHkwb5f2IHA.5728(a)TK2MSFTNGP06.phx.gbl... > George Hester wrote: > > I would like to access just one dimension of a multi-column and > > rows array. Something like if A(i,j) is an array with values for i > > and j how about A(I,j) being just a one-dimensional array? I could > > be say the number of elements i. Thanks. > > VB doesn't natively allow that, but it's possible to fool VB into > thinking it does, depending on how the array is ordered. But it's a > hack, and has to be approached carefully. > > Basically, the idea is to create a blank single-dim array, and > manipulate its SafeArray structure to have the correct bounds, and a > pointer to the data of interest. > > It's not for the inexperienced or the careless, though. You can get > things bollixed up pretty well if you miss a step, or do something you > shouldn't. > > -- > Jim Mack > MicroDexterity Inc > www.microdexterity.com > |