Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Delete from a listbox in vb6.0
07-31-2005, 10:33 PM #1
- Join Date
- Dec 2003
- Thanked 0 Times in 0 Posts
Delete from a listbox in vb6.0
Basically what I am trying to do is find out where in the listbox that the text in text14.text appears in the listbox. That is where the msgbox(smessage) comes in. So for instance if I have this, that, and these in the listbox. How would I find out out the listindex of one of those in the listbox? I have it actually highlighting what is in the listbox. Also the listbox can be sorted or it does not have to be. But can someone help me to find out where my problem is? If I take the comment out of 'List2.RemoveItem Text14.Text then it gives me a type mismatch. Also in the textbox there is just going to be strings and no numberical values in them.
Private Sub Delete_Click() Dim I As Integer Dim sMessage As String sMessage = CInt(Val(Text14.Text)) MsgBox (sMessage) 'If IsNumeric(sMessage) Then 'MsgBox ("1") For I = 0 To List1.ListIndex Step 1 MsgBox ("2") If List1.List(I) = Text14.Text Then List1.RemoveItem I ' Else MsgBox "Value is not numeric" Text14.SetFocus End If Next I 'End If End Subthanks
08-02-2005, 01:16 AM #2
- Join Date
- Sep 2004
- Thanked 40 Times in 40 Posts
I'm not sure if I understand, you want to delete the item in the list box that equals the value of a text box?
Private Sub Delete_Click() Dim i As Integer If List1.ListCount > 0 Then For i = 0 To List1.ListCount - 1 Step 1 If text14.Text = List1.List(i) Then List1.RemoveItem (i) text14.Text = "" text14.SetFocus Exit Sub Else MsgBox (text14.Text & " was not found!") Exit Sub End If Next i Else MsgBox ("The listbox is empty") End If End Sub