Link to home
Start Free TrialLog in
Avatar of vharrig
vharrig

asked on

Removing the first line of a text file

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
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

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
Avatar of vharrig
vharrig

ASKER

Hi VMontalvao ,

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

ASKER

Hi VMontalvao ,

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

try using
 Input #1, trash

Instead of using
 LineInput #1, trash



ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vharrig

ASKER

Thank you for your help, unfortunately the command wouldn't work on my app.
Avatar of vharrig

ASKER

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

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
Avatar of vharrig

ASKER

Thanks