Results 1 to 3 of 3

Thread: Ok some more hlp plz

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    USA - Michigan
    Posts
    94

    Ok some more hlp plz

    I need VB to scan a .txt for a certain line fo text

    then i need to make Num = 1 if that text is there or 0 if not (which i can do, not the question) then if num = 1 print the lines i want and if it = 0 then close and say msgbox "Already set up for use"

    so all i need to know is how to scan a .txt for a certain line of text..thanks
    --Semper Fi--

    --Area 61 Admin--

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    the INSTR() function will search text

    a search turned up this:

    http://www.vbforums.com/showthread.p...light=instring

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    InStr() will work if the text is in memory, which is not what you are saying. However, it is what you SHOULD have been saying. Don't bother trying to scan a text file as a file, I'm not sure that it can be done, and it would be a pain in the but anyways.

    The thing to do, is read the file line by line, and scan each line with InStr(). If you cannot be sure that the string you want lies on a single line, you will have to look for part of the string on one line, and part of the string on a second line, which is slower and tougher, but doable.

    It may seem like reading in the file would be slower than searching for the text in the file, but it isn't. Consider that the program would have to read the file to search it, anyways.

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