Removing the first line of a text file

vharrig
vharrig used Ask the Experts™
on
How can I ignore the first line in a text file, so the file will load. The code below works if I physically remove the first line from the text file.

a = 0
dim Info(500)as String
dim x as integer
Open "MyTextFile" For Input As #1
    Input #1, Info(a)
       Do Until EOF(1)
    Input #1, Info(a)
        a = a + 1
    Loop

Close #1
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
Hi vharrig,

You are very close to the solution.
Try this code:


a = 0

dim Info(500)as String
dim x as integer
dim trash as string

Open "MyTextFile" For Input As #1

'The next line is only to ignore the first line of the file
LineInput #1, trash

Do Until EOF(1)
   Input #1, Info(a)
   a = a + 1
Loop
Close #1


Got it?

Vitor Montalvao

Author

Commented:
Hi VMontalvao ,

The LineInput#1,Trash is giving me a syntax error. Any suggestions?

Author

Commented:
Hi VMontalvao ,

The LineInput#1,Trash is giving me a syntax error. Any suggestions?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Hi,

try using
 Input #1, trash

Instead of using
 LineInput #1, trash



IT Engineer
Distinguished Expert 2017
Commented:
Hi,

Is LineInput #1 (I missed the space, sorry).

Best regards,

Vitor Montalvao

Author

Commented:
Thank you for your help, unfortunately the command wouldn't work on my app.
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
why not?

Author

Commented:
I really don't know. The code would stay Red and if I took out the "Line" part it would fail on me. I got around it by increasing my array and using the Input #1, Info(a) twice. For some reason that works. I'm new to programming and I'm trying. Here is my final result.

Private Sub Form_Load()

a = 0
Dim x As Integer
Dim makea(4, 1000)
Dim lista(1000)
'Open "C:\My Documents\sitepcm1.txt" For Input As #1 ' This is for my computer!!!!
Open "S:\CODenver\Denver Network - DO NOT MOVE THIS FOLDER!!!!\Denver Network - DO NOT MOVE\Denver Switch - DO NOT REMOVE\Tellabs\External_Data_Retrieval\sitepcm.txt" For Input As #1
    Input #1, Info(a)
       Do Until EOF(1)
    Input #1, Info(a)
        a = a + 1
    Loop

Close #1
    For x = 0 To a - 1
    makea(1, x) = Mid(Info(x), 1, 2)
    makea(2, x) = Mid(Info(x), 11, 4)
    makea(3, x) = Mid(Info(x), 24, 3)
    makea(4, x) = Mid(Info(x), 36, 50)
    lista(x) = makea(1, x) & "|" & makea(2, x) & "|" & makea(3, x) & "| " & makea(4, x)
    lista(x) = Replace(lista(x), " ", "")
    Combo1.AddItem lista(x)
Next
End Sub

Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
Well, I don't have VB here in this computer, but I think is LineInput (try to press F1 over the comand).
Or else can be InputLine (I think is not, but you can try too).

In last case press F1 over Input command and see in the help if you can find LineInput (or something close).

Good luck,

Vitor Montalvao

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial