Results 1 to 11 of 11

Thread: [RESOLVED]Search

  1. #1

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Resolved [RESOLVED]Search

    I am searching a document that comes up with for particular values and i need them added to a list box. For example through out my file i may have

    xxxxxxxxxxxxxxxxxxxxxxxxxxxidentification=123,56,78,92xxxxxxxxxxxxxxxxxx

    where x can represent anything. How do i remove the numbers and the comma's only from copy these numbers from the document and add them to a list box. Take into consideration that there will be an unknown amount of lines identical to the ones above.

    Jenova
    Last edited by Jenova; Mar 15th, 2006 at 09:55 AM.

  2. #2
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: Search

    the other characters (x's): May some of them be numbers?

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Search

    You can use InStr() function and loop through each line but I'd recommend to use Reg.Expression so you can set some pattern and get what you want with less effort. We should have some samples available arround here so try searching this forum for "Regular Expression" or similar.

  4. #4

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: Search

    It is a posibility that the (x) may represent numbers as well. Can anyone provide any examples on Rhino bulls idea? I tried the InStr() function. See Below.

    I searched for the identification word in the file and it cam back with an obscene value whic is not correct

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Dim Handle As Integer
    4.     Dim File As String
    5.    
    6.     Handle = FreeFile
    7.     Open "C:\Documents and Settings\Carl\Desktop\index.htm" For Input As Handle
    8.         Do While Not EOF(Handle)
    9.             File = Input(LOF(Handle), #Handle)
    10.             Text1.Text = File
    11.         Loop
    12.     Close #Handle
    13.  
    14. End Sub
    15.  
    16. Private Sub Timer1_Timer()
    17.  
    18.     Static newnum
    19.    
    20.     newnum = InStr(Text1.Text, "identification")
    21.     Command1.Caption = newnum
    22.    
    23. End Sub

    This is what i have so far
    Last edited by Jenova; Mar 14th, 2006 at 05:27 PM.

  5. #5

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: Search

    This is quite a hard one then?

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: [UNSOLVABLE] Search

    try this:

    VB Code:
    1. Private Sub Form_Load()
    2.     Const sFind As String = "identification="
    3.     Dim FileNum As Integer
    4.     Dim sLine As String
    5.     Dim lPos As Long
    6.    
    7.     FileNum = FreeFile
    8.     Open "C:\Documents and Settings\Carl\Desktop\index.htm" For Input As #FileNum
    9.         Do While Not EOF(FileNum)
    10.             Line Input #FileNum, sLine
    11.             lPos = InStr(sLine, sFind)
    12.             If lPos Then List1.AddItem Mid$(sLine, lPos + Len(sFind), 12)
    13.         Loop
    14.     Close #FileNum
    15. End Sub

    Although without knowing the details of what'll be in the file it's hard to tell if that's the solution you need.

  7. #7

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Smile Re: [UNSOLVABLE] Search

    Although without knowing the details of what'll be in the file it's hard to tell if that's the solution you need.
    Thanks for the reply bush mobile. In answer to your question i have included a document that i am supposed to be searching. I have made the information i am seacrching for bold to make it more clear.

    I need all of those values added to a list box. There will be ALOT more than that in the documents i will be scanning.

    Jenova
    Last edited by Jenova; Mar 15th, 2006 at 08:44 AM.

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: [UNSOLVABLE] Search

    Ok, try the below. If it's too slow then maybe you'll have to take RB's advice - Regular Expression

    VB Code:
    1. Private Sub Form_Load()
    2.     Const sFind As String = "domain="
    3.     Dim FileNum As Integer
    4.     Dim sLine As String
    5.     Dim lPos As Long
    6.    
    7.     FileNum = FreeFile
    8.     Open "C:\Documents and Settings\Carl\Desktop\index.htm" For Input As #FileNum
    9.         Do While Not EOF(FileNum)
    10.             Line Input #FileNum, sLine
    11.             lPos = InStr(sLine, sFind)
    12.             If lPos Then List1.AddItem Mid$(sLine, lPos + Len(sFind), Instr(lPos, sLine, Chr(34)) - lPos + Len(sFind)))
    13.         Loop
    14.     Close #FileNum
    15. End Sub

  9. #9

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: [UNSOLVABLE] Search

    Thanks alot, that works great. Only have two questions

    What are the following variables for:
    sLine
    lPos

    Jenova

  10. #10
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: [UNSOLVABLE] Search

    Line Input #FileNum, sLine
    This tells VB to put the whole line from the file into a string variable called sLine

    lPos = InStr(sLine, sFind)
    This returns the character position of sFind in sLine. It returns zero if it's not present. We know where the text we want is in relation to lPos, so once we've got it we can extract the text using the Mid Function.

    Don't forget to mark this thread resolved if your question has been answered

  11. #11

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: [RESOLVED]Search

    Thank you!

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