PDA

View Full Version : Solved: Resizing Array



JKwan
04-11-2011, 08:56 AM
I have a listbox that I populated with an array
listbox1.list = myarray

now, I changed the list box and I want to reassign it back to my array (myarray = listbox1.list), but it returns as a 2 dimensional array, which I don't want, I wanted it to be a one dimensional array. I know that I need to use the RESIZE command, however, I am pulling my hair off and not working.

Thanks in advance

GTO
04-11-2011, 09:11 AM
You can try this, but please note that .Transpose will return a 1-based array. As long as your input array is 1-based, I think it should work.
Dim ary

ary = Array("Bill", "Tom", "Seth")
Me.ListBox1.List = ary

ary = Application.Transpose(Me.ListBox1.List)

JKwan
04-11-2011, 09:17 AM
Thanks GTO, it is coming back with a one dimensional array, however, it is coming back starting with 1, not 0. Is there a way to make it 0 based?

Thanks again.

JKwan
04-11-2011, 09:30 AM
Don't worry about it, I wrapped my code with an IF statement to overcome this minor problem.

Thanks again.

GTO
04-11-2011, 09:39 AM
I do not believe so. Whichever is easier, feed the array in as a 1-based array, or loop the .List back into a 0-based. For the second, maybe:
Dim ary, aryTmp, i As Long

ary = Array("Bill", "Tom", "Seth")
Me.ListBox1.List = ary
ary = Me.ListBox1.List

ReDim aryTmp(LBound(ary, 1) To UBound(ary, 1))

For i = LBound(ary, 1) To UBound(ary, 1)
aryTmp(i) = ary(i, 0)
Next

ary = aryTmp