![]() |
Passing a list to an array
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 |
Passing a list to an array
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 "Matt" wrote in message ups.com... 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 |
Passing a list to an array
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 Jim Cone wrote: 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 "Matt" wrote in message ups.com... 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 |
Passing a list to an array
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" 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 Jim Cone wrote: 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 "Matt" wrote in message ups.com... 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 |
All times are GMT +1. The time now is 06:08 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com