i want to do a search in a listbox This is the code I've written but not working properly formats you some idea

If TextBox1.Text = ListBox1.Name Then

            MsgBox("true name")
        Else
            MsgBox("false name")
        End If

thanks for help

Okay, First, let me explain the Name property for you. The Name property is the name of the control. Second, ListBox1 tells me that you are using VBA controls like the ones found in access, excel, word, which means this is a VBA question and not a VB question.

Now in vb we would loop through from zero to list1.listcount-1 searching for if text1.text = list1.list(loopcounter) to see if we have found a match as that is what it looks like you are trying to do, but from that small snippit, it is hard to tell.

Good Luck

The comparison is case sensitive on VB.
So, if you don't type the EXACTLY name of your component, it will not work - always return "false name".

BUT, if you want to search in the ITEMS of that listbox, you need to create a loop statement, like

Dim nCont as Integer

For nCont = 0 to ListBox1.ListCount - 1
  If UCase(TextBox1.Text) = UCase(ListBox1.List(nCont)) then
    MsgBox "Encontrou"
  End If
Next

The message appears only if the text in textbox match a item in the listbox, and the UCase function compares both sides in upper case.


Sidnei

i want to do a search in a listbox This is the code I've written but not working properly formats you some idea

If TextBox1.Text = ListBox1.Name Then

            MsgBox("true name")
        Else
            MsgBox("false name")
        End If

thanks for help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.