Deleting Lines From Text File

GregSmith

Registered User.
Local time
Today, 17:46
Joined
Feb 22, 2002
Messages
126
I have a text file that I import into Access but need to remove the 1st 6 lines of data. Does anyone have any VB code that will allow me to do this?
 
I keep running into similar problems. (I presume you want this done repeatedly?)

I would perform this operation in word.

To find code to operate word, I often find it useful to create a macro (in word), and then look at the code.

Having done this, you can either open up word and call on the macro, or you can probably run the operations directly in your code.

Fuga.
 
I found away to keep it all within Access.
I have it open the file for input #1 and open for output #2.
I then read the line in and do a linex=linex+1
I then look to see if x>7 (i only need the first 6 lines deleted) then if it is, start print #2, mystring

Then I have it close delete the old file and rename the new file to the old filename. Works like a charm!!
 
Good idea!

I think maybe I´m going to try that the next time.

Fuga.
 
I've been looking to do this exact thing! I've been searching the net for a while and came across this forum!

I know I've dragged up an ancient post, but can anyone help clarify the code needed for this for me!?

If I want to take "file1.txt" and remove/clear the 1st 8 lines, what is the exact code to put into my access program?

I'm an absolutle beginner at this stuff, so anybody's help would be very very much appreciated! :)
 
I think this is what Gregsmith meant.

PHP:
Sub clearlines()
Dim lineX As Integer
Dim mytext As String

Open "c:\File1.txt" For Input As #1
Open "c:\File2.txt" For Output As #2
lineX = 1

Do While Not EOF(1)
    Line Input #1, mytext
    If lineX >= 9 Then
    Print #2, mytext
    End If
    lineX = lineX + 1
Loop
Close #1
Close #2
Kill "c:\File1.txt"
FileCopy "c:\File2.txt", "c:\File1.txt"
End Sub

This will write the text in file1, save for the first 8 lines, to file2. Then file2 replaces file1.
Fuga.
 

Users who are viewing this thread

Back
Top Bottom