List box help with vb

M

mike

Hi all,

I posted an article regarding with the list box multi-
selection and repost the article with the solution solve.
Actually, I still need help in the list box multi-
selection. I found the solution to get the items that are
selcted from the list box. Now, I'm stuck in extracting
the items and put the items to another array.

My list box have the values in it and all of them is
selected.

User list box:

Last Name | First Name
Doe John
Doe John Jr.


Here is my code to get the selected items

Dim Ctl As Control
Dim varItm As Variant, intI As Integer, i As Integer,
ccount As Integer
Dim str As String, uname(20) As String, uholder(20) as
string

i = 0
ccount = 0
Set Ctl = Me.UserResult
For Each varItm In Ctl.ItemsSelected
For intI = 0 To Ctl.ColumnCount - 1
str = str & " " & Ctl.Column(intI, varItm)
Next intI
uname(i) = str
str = ""
i = i + 1
ccount = ccount + 1
Next varItm

The uname(0) array holds the string value of (Doe John)
and so on. Now, I'm geting stuck on extracting the uname
array and assign it to another array by using the
following code:

For j = 0 To ccount - 1
uholder(j)=Split(uname(j)," ")
** The above line should split the uname array and
assigned the value to uholder array. The result of the
uholder array should be uholder(0)=Doe and uholder(1)
=John. But the code doesn't work. Please help........

Thanks for the help

mike.
 
B

Bryan Reich [MSFT]

Mike,
Try this as an alternative.

Dim nameParts() as string ' notice this is not an array with a set number of
elements

'<do your code to get names from box here>

For Each str In names
nameParts = split(str, " ")
' Notice that you aren't assigning to an individual index in the name
parts but instead you're assigning the entire array. That was what was
causing you problems before.
'<do what you need to do with the name parts here>
Next


See how this works for your purposes.
 

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