Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    texas
    Posts
    96
    Thanks
    1
    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.

    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
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    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?
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •