Web Analytics Made Easy -
StatCounter Delete from a listbox in vb6.0 - CodingForum

Announcement

Collapse
No announcement yet.

Delete from a listbox in vb6.0

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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.

    Code:
    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 Sub
    thanks
    bri

  • #2
    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?
    Code:
    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
    -Brando
    Why using tables for eating is stupid!

    Comment

    Working...
    X