CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Finding Data

  1. #1
    Join Date
    Jul 2000
    Posts
    124

    Finding Data

    I have a whole bunch of text in a document and I want to find each time it has a specific word in it and I want to display that word each time in a listbox. Where do I start?

    Thanks!
    Erica


  2. #2
    Join Date
    Aug 2000
    Location
    KY
    Posts
    766

    Re: Finding Data

    look at the LIKE operator in the help file it should do the trick and you can use wildcard characters with it.

    Hope this helps



  3. #3
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Finding Data

    Not sure what exactly you want to do. If you have a bunch of texts and you want to display the occurrences of specific word, that means you'll be populating the listbox with the same word again and again. Anyway, you can try to look at the following functions:

    1. Open to open the text file
    2. EOF() to determine end-of-file while reading
    3. Line Input to read line by line
    4. InStr() to search for specific word in a bunch of texts
    5. .AddItem method of ListBox to add new text into the list.

    Hope this helps,
    -Cool Bizs

    Good Luck,
    -Cool Bizs

  4. #4
    Join Date
    Jul 2000
    Posts
    124

    Re: Finding Data

    Thanks for those tips. What I'm trying to do is find how many images are in a document, so I'm using the innerhtml method to get the source code, but now I need to get a list of all the images in it. So I thought if I found every time it used a <img> I could then use the right() to get the name. Do you have any suggestions?

    Thanks!
    Erica


  5. #5
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Finding Data

    Ooo okay. Consider the following code:


    Sub SearchImageTags(szHTML as string)
    dim szBuffer as string
    dim nCurInd as long
    dim nStartInd as long

    ' uppercase to easy search
    szHTML = UCase(szHTML)

    ' clear current list
    List1.Clear

    ' get the first <IMG
    nStartInd = 1
    nCurInd = InStr(nStartInd, szHTML, "<IMG")

    ' loop until nCurInd = 0
    while (nCurInd <> 0)
    nStartInd = nCurInd ' save the index of the <
    nCurInd = InStr(nStartInd+1, szHTML, ">") ' look for the ending >
    if (nCurInd <> 0) then
    ' found it - retrieve the tag (clean it as you see fit)
    szBuffer = mid$(szHTML, nStartInd, (nCurInd - nStartInd))
    List1.AddItem szBuffer

    ' advance the start index
    nStartInd = nCurInd + 1
    nCurInd = InStr(nStartInd, szHTML, "<IMG")
    end if
    wend
    End Sub




    I have it really tested the code so work with it to make it work.
    -Cool Bizs

    Good Luck,
    -Cool Bizs

  6. #6
    Join Date
    Jul 2000
    Posts
    124

    Re: Finding Data

    Thank you for your help!


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

Featured