Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Remove a line from a text file

I use a text file to hold information but I need to be able remove a line of
data, I was wondering if this is possible I have tried to inforamtion on this
without success.
Can any body please help.
TIA
Charles
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Remove a line from a text file

You have to create a new text file with the line no longer requirted removed

This is some code to remove a file header:

Function RemoveHeader(ByVal strOldFileName As String, _
ByVal strNewFileName As String) As Variant

'function removes header from strOldFileName
'creating strNewFileName and returning an array of the record count
and the removed header


Dim strLineOld As String 'Current line
Dim hFileOld As Long 'Handle on old file
Dim hFileNew As Long 'Handle on new file
Dim intI As Integer 'Counter
Dim strHeader As String 'header removed
Dim lngLineCountOld As Long 'recordcounter

'set up error handler
On Error GoTo ProcError

'get file handles
hFileOld = FreeFile
hFileNew = FreeFile + 1

'open up files
Open strNewFileName For Output As hFileNew
Open strOldFileName For Input As hFileOld

'get header from first line
Line Input #hFileOld, strLineOld
strHeader = strLineOld


Do Until EOF(hFileOld)
'get the next line of old file
'and write it to new file
Line Input #hFileOld, strLineOld
lngLineCountOld = lngLineCountOld + 1
Print #hFileNew, strLineOld
Loop
RemoveHeader = Array(lngLineCountOld, strHeader)

ProcExit:
'close files
Close hFileOld
Close hFileNew
DoCmd.Echo True
Exit Function
ProcError:
DoCmd.Echo True
MsgBox Error(Err)

Resume ProcExit


End Function

"vqthomf" wrote:

I use a text file to hold information but I need to be able remove a line of
data, I was wondering if this is possible I have tried to inforamtion on this
without success.
Can any body please help.
TIA
Charles

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Remove a line from a text file

Thanks I give it a try.
Regards

"DomThePom" wrote:

You have to create a new text file with the line no longer requirted removed

This is some code to remove a file header:

Function RemoveHeader(ByVal strOldFileName As String, _
ByVal strNewFileName As String) As Variant

'function removes header from strOldFileName
'creating strNewFileName and returning an array of the record count
and the removed header


Dim strLineOld As String 'Current line
Dim hFileOld As Long 'Handle on old file
Dim hFileNew As Long 'Handle on new file
Dim intI As Integer 'Counter
Dim strHeader As String 'header removed
Dim lngLineCountOld As Long 'recordcounter

'set up error handler
On Error GoTo ProcError

'get file handles
hFileOld = FreeFile
hFileNew = FreeFile + 1

'open up files
Open strNewFileName For Output As hFileNew
Open strOldFileName For Input As hFileOld

'get header from first line
Line Input #hFileOld, strLineOld
strHeader = strLineOld


Do Until EOF(hFileOld)
'get the next line of old file
'and write it to new file
Line Input #hFileOld, strLineOld
lngLineCountOld = lngLineCountOld + 1
Print #hFileNew, strLineOld
Loop
RemoveHeader = Array(lngLineCountOld, strHeader)

ProcExit:
'close files
Close hFileOld
Close hFileNew
DoCmd.Echo True
Exit Function
ProcError:
DoCmd.Echo True
MsgBox Error(Err)

Resume ProcExit


End Function

"vqthomf" wrote:

I use a text file to hold information but I need to be able remove a line of
data, I was wondering if this is possible I have tried to inforamtion on this
without success.
Can any body please help.
TIA
Charles

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove headers from text file Hilton Excel Discussion (Misc queries) 4 November 6th 07 03:04 PM
remove line breaks in text strings Capn Swing New Users to Excel 1 January 2nd 07 04:54 PM
Reading a text file line by line stressman Excel Programming 3 October 16th 05 05:29 AM
Reading a text file line by line Foss[_2_] Excel Programming 4 March 16th 05 04:01 PM
import huge text file line-by-line? rachel Excel Programming 2 November 6th 04 04:43 PM


All times are GMT +1. The time now is 01:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"