What is the best way to count lines in file?

In Vb6, is there a way to go back some n lines before the main line when reading a file?

  • I am trying to extract some portions of a file. When a keyword is found, I will get the first few lines before it and output it in a file. is there a way for this in vb6? any ideas? thanks.

  • Answer:

    Simply read the whole file into an array. You can then loop through the array quite easily to find your keyword and get the previous lines. ie. Let's call the array LINES(). If the keyword is on LINES(27), then you could easily iterate backwards to get LINES(26), LINES(25) and LINES(24). Does that make sense? If not, contact me and I'll write some code for you tonight.

clueless at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.