Passing a list to an array

M

Matt

Just curious to know if it is possible to convert a listbox of values
to an array, such as:

Dim arrA as variant
with me.listbox1
arrA = array(.list)
end with

Seems like functionality that would make sense.
It's a pain to do the for i = 0 to .listcount - 1 thing to
create an array.

TIA,
Matt
 
J

Jim Cone

Matt,

With a small change...remove "array".

Dim arrA As Variant
arrA = Me.ListBox1.List
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


Just curious to know if it is possible to convert a listbox of values
to an array, such as:

Dim arrA as variant
with me.listbox1
arrA = array(.list)
end with

Seems like functionality that would make sense.
It's a pain to do the for i = 0 to .listcount - 1 thing to
create an array.

TIA,
Matt
 
M

Matt

Thanks Jim but oddly the code below didn't work in 2002 for
me...probably missed something dumb

Private Sub CommandButton1_Click()
Me.ListBox1.AddItem Me.TextBox1
End Sub

Private Sub CommandButton2_Click()
Dim arrVariant As Variant
arrVariant = Me.ListBox1.List
MsgBox arrVariant(0) ' type 13 err
End Sub

TIA,
Matt
 
J

Jim Cone

That array returned by the .list property (for a single column) is a 2 dimensional array.
So you have to specify the column as well as the row...
Msgbox arrVariant(0, 0)
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html



"Matt" <[email protected]>
wrote in message
Thanks Jim but oddly the code below didn't work in 2002 for
me...probably missed something dumb

Private Sub CommandButton1_Click()
Me.ListBox1.AddItem Me.TextBox1
End Sub

Private Sub CommandButton2_Click()
Dim arrVariant As Variant
arrVariant = Me.ListBox1.List
MsgBox arrVariant(0) ' type 13 err
End Sub

TIA,
Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top