ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete first line line(s) of text-file? (https://www.excelbanter.com/excel-programming/419028-delete-first-line-line-s-text-file.html)

Charlotte E.[_2_]

Delete first line line(s) of text-file?
 
I have a spreadsheet that writes some logging of its approach to a
text-file, using:

Open LOGFile For Append As #FileNumber


However, over time this text-file just keeps on growing!
And, I really just need to be able to see the latest entries :-)


Is there any way to determine of the text file has grown to, say 100 lines?
And, if there is, is there any way to delete all, but the last 100, lines in
the text file?

Using Append makes the last 100 lines in the text file into the 100 latest
entries, so it really need to be the first lines of the text file that get
deleted...

And it is not an option to delete the text file, since the logging only
makes around 10 lines a day, and I need to be able to view at least a week
back, thus approx. 100 lines...


Can this be achived?


TIA,

CE



Gary Keramidas

Delete first line line(s) of text-file?
 
here's an abbreviated, untested method, though i don't know how you're opening
the files. it also doesn't test to see if there are more than 100 lines, it's
just a concept:

'open of the file
cntr1 = 0 ' sets the initial value
Do Until Fn = ""
Open FileDir & Fn For Input Access Read As #1

' ------determine number of lines
While Not EOF(1)
Line Input #1, WholeLine
cntr1 = cntr1 + 1
Wend
'-------------

Debug.Print cntr1, Fn ' print the number of lines and the filename to the
immediate window

for i = cntr1 -100 to cntr1 ' gets to the last 100 lines
Line Input #1, WholeLine
next

'here's where you code to manipulate the file goes

cntr1 = 0 ' reset the counter
Close #1
Fn = Dir()
Loop

--


Gary

"Charlotte E." <@ wrote in message ...
I have a spreadsheet that writes some logging of its approach to a text-file,
using:

Open LOGFile For Append As #FileNumber


However, over time this text-file just keeps on growing!
And, I really just need to be able to see the latest entries :-)


Is there any way to determine of the text file has grown to, say 100 lines?
And, if there is, is there any way to delete all, but the last 100, lines in
the text file?

Using Append makes the last 100 lines in the text file into the 100 latest
entries, so it really need to be the first lines of the text file that get
deleted...

And it is not an option to delete the text file, since the logging only makes
around 10 lines a day, and I need to be able to view at least a week back,
thus approx. 100 lines...


Can this be achived?


TIA,

CE




Gary Keramidas

Delete first line line(s) of text-file?
 
it was late when i did this, this line

for i = cntr1 -100 to cntr1 ' gets to the last 100 lines

should be

for i = 1 to cntr1 -100 ' gets to the last 100 lines


--


Gary

"Gary Keramidas" <GKeramidasAtMsn.com wrote in message
...
here's an abbreviated, untested method, though i don't know how you're opening
the files. it also doesn't test to see if there are more than 100 lines, it's
just a concept:

'open of the file
cntr1 = 0 ' sets the initial value
Do Until Fn = ""
Open FileDir & Fn For Input Access Read As #1

' ------determine number of lines
While Not EOF(1)
Line Input #1, WholeLine
cntr1 = cntr1 + 1
Wend
'-------------

Debug.Print cntr1, Fn ' print the number of lines and the filename to the
immediate window

for i = cntr1 -100 to cntr1 ' gets to the last 100 lines
Line Input #1, WholeLine
next

'here's where you code to manipulate the file goes

cntr1 = 0 ' reset the counter
Close #1
Fn = Dir()
Loop

--


Gary

"Charlotte E." <@ wrote in message
...
I have a spreadsheet that writes some logging of its approach to a text-file,
using:

Open LOGFile For Append As #FileNumber


However, over time this text-file just keeps on growing!
And, I really just need to be able to see the latest entries :-)


Is there any way to determine of the text file has grown to, say 100 lines?
And, if there is, is there any way to delete all, but the last 100, lines in
the text file?

Using Append makes the last 100 lines in the text file into the 100 latest
entries, so it really need to be the first lines of the text file that get
deleted...

And it is not an option to delete the text file, since the logging only makes
around 10 lines a day, and I need to be able to view at least a week back,
thus approx. 100 lines...


Can this be achived?


TIA,

CE






Charlotte E.[_2_]

Delete first line line(s) of text-file?
 
Sorry for a late reply, but I've spendt the week-end playing with your
code-example :-)

Got it to work - thanks :-)


CE



Charlotte E. wrote:
I have a spreadsheet that writes some logging of its approach to a
text-file, using:

Open LOGFile For Append As #FileNumber


However, over time this text-file just keeps on growing!
And, I really just need to be able to see the latest entries :-)


Is there any way to determine of the text file has grown to, say 100
lines? And, if there is, is there any way to delete all, but the last
100, lines in the text file?

Using Append makes the last 100 lines in the text file into the 100
latest entries, so it really need to be the first lines of the text
file that get deleted...

And it is not an option to delete the text file, since the logging
only makes around 10 lines a day, and I need to be able to view at
least a week back, thus approx. 100 lines...


Can this be achived?


TIA,

CE




Gary Keramidas

Delete first line line(s) of text-file?
 
as long as you found an answer somewhere, somehow, that's all that matters.

--


Gary

"Charlotte E." <@ wrote in message ...
Sorry for a late reply, but I've spendt the week-end playing with your
code-example :-)

Got it to work - thanks :-)


CE



Charlotte E. wrote:
I have a spreadsheet that writes some logging of its approach to a
text-file, using:

Open LOGFile For Append As #FileNumber


However, over time this text-file just keeps on growing!
And, I really just need to be able to see the latest entries :-)


Is there any way to determine of the text file has grown to, say 100
lines? And, if there is, is there any way to delete all, but the last
100, lines in the text file?

Using Append makes the last 100 lines in the text file into the 100
latest entries, so it really need to be the first lines of the text
file that get deleted...

And it is not an option to delete the text file, since the logging
only makes around 10 lines a day, and I need to be able to view at
least a week back, thus approx. 100 lines...


Can this be achived?


TIA,

CE







All times are GMT +1. The time now is 05:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com