Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read a text file, count lines and pages

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am new to vb!

I would like to read in a text file, count the # of lines, for every 66 lines read, place that data into a page array until the EOF is reached.

Then i would like to output these pages to a new file but add a new line with a date, and Page #, etc... to every page.

thanks
newbie_999
 
Theres no need to use an array, just write the new file line by line as you read the old one. Use the MOD function to check when the line is a multiple of 66. MOD returns the remainder of a division. So LineNumber MOD 66 will return zero once every 66 lines.

Code:
Dim FileLine As String 
Dim Pages As Long 
Dim Lines As Long 

Open "C:\Filename.txt" For Input As #1 
Open "C:\NewFile.txt" For Output As #2 

Pages = 0 
Lines = 0 

While Not EOF(1) 
   Line Input #1, FileLine 
   Print #2, FileLine 
   Lines = Lines + 1 
   If Lines MOD 66 = 0 Then 
      Pages = Pages + 1 
      Print #2, "Page " & Pages & " " & Date() 
   End If 
Wend 

Close #1 
Close #2
Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Thanks for all your help!

However, now i have a different problem... The files i am reading in have line feeds that separate the pages...

Can you help me...

I would like to read in a text file, search each line for a vbLf.

Then i would like to output these pages to a new file but add a new line with a date, and Page #, etc... to every page.

thanks
newbie_999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top