Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to VB Need help with List Boxes

Status
Not open for further replies.

Jewel142

ISP
Jun 17, 2009
39
Hi Everyone,

I am new to VB and need help with a project. I have a user-interface that has a list box with employee's names added to it (Debbie, John, Jim, etc) which are defined as strings. On my form, there is a select single name button and select multiple name button. There is also display label which displays the name or names the user selects.

My select singleNameButton is working correctly using nested ElseIf statements.

I have gone round and round trying to get my multiple select button working. I've tried nested if statements, the FindStringExact Method. I have written and rewritten my code and have completely scrapped it all in complete frustration.

I know that this is probably pretty simple but I've been looking at it for so long I can't see straight.

Any help would be greatly appreciated!!
 
This is a very simple example of how to use a Listbox with the multiselect property.

Create a new project, and add a Listbox and a Command button. Change the Listbox's "MultiSelect" property to "2-Extended". Paste in the code below and run it. Select one or more names from the list (using CTRL-Click to highlight more than one name), and the Command button will show you which names you selected.

Code:
Option Explicit

Private Sub Form_Load()
   List1.AddItem "Aaron"
   List1.AddItem "Bob"
   List1.AddItem "Charlie"
   List1.AddItem "Dan"
   List1.AddItem "Eric"
End Sub

Private Sub Command1_Click()
   Dim sSelectedNames As String
   Dim i As Integer
   
   For i = 0 To List1.ListCount - 1
      If List1.Selected(i) = True Then
         sSelectedNames = sSelectedNames & List1.List(i) & " "
      End If
   Next
   
   MsgBox sSelectedNames

End Sub
 
Thanks for your help! I'll let you know how I make out. Have a great day!

Jewel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top