0

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

Edited by olgar: n/a

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by sidnei
0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.