Results 1 to 26 of 26

Thread: Searching Textboxes and Listboxes and dropdown lists

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Searching Textboxes and Listboxes and dropdown lists

    Well, im back again , arent u so happy? well anyway, i need a search that will search textboxes listboxes and dropdrown lists and return a list of Links that will hide and show textboxes

    im guessing that this is possible, but i have no clue where to start, could somebody help me out a little, not write the whole script or anything (unless u wanna) but just give me a basis for the search

  2. #2
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: Searching Textboxes and Listboxes and dropdown lists

    Where do you expect to get these textboxes, listboxes, or comboboxes from? I don't quite understand what you mind but it will return a list of links. Are you looking to say, look for all textboxes in your app and be able to hide them? Please be a bit more clear.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Re: Searching Textboxes and Listboxes and dropdown lists

    ok, i have a textbox with a submit button, i want the words inside the textboxed to be searched for from multiple textboxes, lisboxes, and comboboxes that i have hidden in my app and i want it to return a list of links that will show the textbox the word is in when clicked. make sense?

  4. #4
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: Searching Textboxes and Listboxes and dropdown lists

    Yeah a bit. So all of the textboxes that you want to search FOR are in your app?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Re: Searching Textboxes and Listboxes and dropdown lists

    i want to search through, like lets say i have 5 articles, i want to find any mention of the word vista, so i type in vista and press submit, and it lists all the articles that have vista in it and i click on one and it takes me there

    i already got the UI and search box done, i just need the code to search and display the results

  6. #6
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Searching Textboxes and Listboxes and dropdown lists

    Quote Originally Posted by PHil_ROX
    i want to search through, like lets say i have 5 articles, i want to find any mention of the word vista, so i type in vista and press submit, and it lists all the articles that have vista in it and i click on one and it takes me there

    i already got the UI and search box done, i just need the code to search and display the results
    You will find your code to be much simpler if all the hidden text boxes are inside a control array. Then you loop through each of them and look for a match. Isolate your search to within the Submit command button click event. A list box can be used to collect all the matched results.
    Doctor Ed

  7. #7
    Lively Member
    Join Date
    Nov 2007
    Location
    Rochester, NY
    Posts
    111

    Re: Searching Textboxes and Listboxes and dropdown lists

    The following examples are using InStr (In String), which will go through the designated string and look for the provided data.
    Syntax:
    vb Code:
    1. InStr(Start At Character, String One(your input data), String Two(what we're looking for), What type of comparison)

    Searching in textbox:
    vb Code:
    1. If InStr(1, Text1.Text, Text2.Text, vbTextCompare) Then
    2.     MsgBox("Found " & Text1.Text)
    3.     Exit Function
    4. End If

    Searching a listbox:
    vb Code:
    1. Function SearchTextString()
    2. Dim N As Long
    3. If Text1.Text = "" Then Exit Function
    4.  
    5. For N = 0 To List1.ListCount - 1
    6. If InStr(1, Text1.Text, List1.List(N), vbTextCompare) Then
    7.     MsgBox("Found " & (N))
    8.     Exit Function
    9. End If
    10. Next N

    Hope it helps =)
    Please use the search function prior to posting a question and see if someone's already answered it.
    -If I helped you, please rate me, as I'd do the same for you =)
    -Remember to select the Resolved option for your post when you've gotten the answers you need.

  8. #8
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: Searching Textboxes and Listboxes and dropdown lists

    Are the textboxes in another app though?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Re: Searching Textboxes and Listboxes and dropdown lists

    they are in the same app

    @neato thanks for the start, it helps alot

  10. #10
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: Searching Textboxes and Listboxes and dropdown lists

    Oh ok. Then go with neato. It's much easier that way.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Re: Searching Textboxes and Listboxes and dropdown lists

    i didnt really get what you said anyway lol

  12. #12
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: Searching Textboxes and Listboxes and dropdown lists

    lol. Let's just say if the textboxes were in another app it would be a lot harder to read them.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Re: Searching Textboxes and Listboxes and dropdown lists

    thanks guys for all your help, just one more question, after i get them into a list, is it possible to make the results into links that take you to the textbox or listbox and highlight them? and if its a long list or paragrapgh, take you to that section of it... do you get what im saying?

  14. #14
    Fanatic Member louvelle's Avatar
    Join Date
    Jun 2008
    Posts
    513

    Re: Searching Textboxes and Listboxes and dropdown lists

    Quote Originally Posted by Neato
    The following examples are using InStr (In String), which will go through the designated string and look for the provided data.
    Syntax:
    vb Code:
    1. InStr(Start At Character, String One(your input data), String Two(what we're looking for), What type of comparison)

    Searching in textbox:
    vb Code:
    1. If InStr(1, Text1.Text, Text2.Text, vbTextCompare) Then
    2.     MsgBox("Found " & Text1.Text)
    3.     Exit Function
    4. End If

    Searching a listbox:
    vb Code:
    1. Function SearchTextString()
    2. Dim N As Long
    3. If Text1.Text = "" Then Exit Function
    4.  
    5. For N = 0 To List1.ListCount - 1
    6. If InStr(1, Text1.Text, List1.List(N), vbTextCompare) Then
    7.     MsgBox("Found " & (N))
    8.     Exit Function
    9. End If
    10. Next N

    Hope it helps =)
    Umm...Can this code be used in a datagrid?

    Manny Pacquiao once posted in his twitter:
    It doesn't matter if the grammar is wrong, what matter is that you get the message

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Searching Textboxes and Listboxes and dropdown lists

    I don't know about a datagrid (never use them), but it could be easily modified for a Listview.

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Re: Searching Textboxes and Listboxes and dropdown lists

    ok, i finally got around to working on my app again and i got some questions

    what should i put here
    InStr(Start At Character, String One(your input data), String Two(what we're looking for), What type of comparison)

    at first i thought it was what the user was searching for, but it wasnt...

    i used this fuction without the above and no matter what, i always get a message box saying it found what i was searching for even tho it doesnt exist. my guess is its because of the lack of the syntax but maybe not
    Code:
          If InStr(1, Text1.Text, Text2.Text, vbTextCompare) Then
              MsgBox("Found " & Text1.Text)
              Exit Function
          End If

  17. #17
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: Searching Textboxes and Listboxes and dropdown lists

    try:

    Code:
      If InStr(1, Text1.Text, Text2.Text, vbTextCompare)>0 Then
              MsgBox("Found " & Text1.Text)
              Exit Function
          End If

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Re: Searching Textboxes and Listboxes and dropdown lists

    ok, that works better, idk if this is the best way to do it, but im gonna have it search the boxs one at a time, if it finds it, add it to a invisible listbox and move it on to the next box by the way of a if inside a if and if it doesnt find it, move on anyway

    so basically, like this

    Code:
      If InStr(1, Text1.Text, Text2.Text, vbTextCompare)>0 Then
              'add to listbox
              If InStr(1, Text1.Text, Text2.Text, vbTextCompare)>0 Then
                     MsgBox("Found " & Text1.Text)
                    If InStr(1, Text1.Text, Text2.Text, vbTextCompare)>0 Then
                          'add to listbox
                    Else
                    
                    End If 
      Else        
              If InStr(1, Text1.Text, Text2.Text, vbTextCompare)>0 Then
                    'add to listbox
              Else
                    
              End If
      End If
    and so on. is ther a better way?

  19. #19
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: Searching Textboxes and Listboxes and dropdown lists

    Use a recursive sub. Put only one instance of the if instr(.... end if part in a sub, and from that sub call the sub if the text is found.

    for example:


    Code:
     
    Private sub AddToBox
     If InStr(1, Text1.Text, Text2.Text, vbTextCompare)>0 Then
              'add to listbox
              addtobox
      Else        
              If InStr(1, Text1.Text, Text2.Text, vbTextCompare)>0 Then
                    'add to listbox
              Else
                    
              End If
      End If
    End sub

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Re: Searching Textboxes and Listboxes and dropdown lists

    well, i just found out sumting that really sucks, when i tested the search i just had one word in there, but when i accually put a paragraph in and searched. it returned negative every time unless i copied and pasted the whole paragraph into the searchbox

  21. #21
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: Searching Textboxes and Listboxes and dropdown lists

    weird...send me your code through pm i'll see what i can do.. it's hard to picture the problem

  22. #22

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Re: Searching Textboxes and Listboxes and dropdown lists

    done

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Re: Searching Textboxes and Listboxes and dropdown lists

    still waiting... lolz

  24. #24
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: Searching Textboxes and Listboxes and dropdown lists

    I know. I had just left the office when I made that post. Most of my work is done from my office M-F 8-5. It's 8:30 now. I'll do my best to take a look at it by the end of the day.

  25. #25
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Searching Textboxes and Listboxes and dropdown lists

    Moved To VB.NET

  26. #26

    Thread Starter
    Junior Member
    Join Date
    Jul 2008
    Posts
    27

    Re: Searching Textboxes and Listboxes and dropdown lists

    oops, guess i had the wrong section...

Posting Permissions

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



Click Here to Expand Forum to Full Width