By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,893 Members | 1,757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,893 IT Pros & Developers. It's quick & easy.

search in text file problems

P: 36
hi all

i search about statement in text file by this code :

Expand|Select|Wrap|Line Numbers
  1. LineFlag = LineFlag + 1
  2.       Line Input #1, strLine
  3. If LineFlag = 15 Then
  4.         If InStr(1, strLine, " Transfer completed successfully.") <> 0 Then
  5.             MsgBox "successful"
  7.             Else
  8.             MsgBox "failed", vbExclamation, ""
  9.            End If
  10.         End If
but the problem some times the text file contains less than 15 lines and the program get out of if statement.

i want search about statement without write the line number .
i want the program search about statement in file without specified line number .

example :

the program search in text file about this statement : "Transfer completed successfully".
if the program found this statement in any place in text file it shows message box .

thank you
Mar 7 '07 #1
Share this Question
Share on Google+
3 Replies

Expert 5K+
P: 8,434
That's fairly simple. Just do the following...
  • Ignore the line number
  • After showing your "successful" msgbox, set a flag to say you did, then exit the loop.
  • Remove the Else clause
  • After the end of the loop, if your flag is not set, then show the "failed" msgbox.
Mar 7 '07 #2

P: 36
can you explain this steps by code
thank you
Mar 7 '07 #3

P: 13
There is no need to count lines if you are just looking for the end of file

Expand|Select|Wrap|Line Numbers
  2. do
  3.       Line Input #1, strLine'
  4. loop until eof(#1)
  5. msgbox "File has ended"
Mar 9 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.