skip 26 line in txt file

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

skip 26 line in txt file

Post by sal21 »

I use the tipical Open c:\..... for output #1 ecc.... to loop approx 134.000 lines in txt file.
In the txt file are 26 (with the same struttcture and position) not are important to my project.

Now i use a:

If not mid(riga, x,y)="zzzzz" and not .... ecc. and not .... ecc. and not .... ecc.then

...

end if

to skip the 26 lines

But sure i think exists other and fasted method to skip the not important lines, or not?

note:
is in effect a block of lines is similar to and init and finish with line1 line26:

line1
line2
line3

...

line26

Becks
2StarLounger
Posts: 196
Joined: 31 Mar 2011, 03:41
Location: Perth, Western Australia

Re: skip 26 line in txt file

Post by Becks »

The simplest method is to loop over those lines without processing them

When you reach the lines in question:

Code: Select all

        For i = 1 To 26
        Line Input #1, sLine
    Next i
Kevin

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: skip 26 line in txt file

Post by HansV »

Are those 26 lines the first 26 in the file, or do they occur somewhere else in the file?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: skip 26 line in txt file

Post by sal21 »

HansV wrote:Are those 26 lines the first 26 in the file, or do they occur somewhere else in the file?
somewhere else in the file...

i can have:

INIZIO:
...
< 26 lines>
...
FINE:
good line
good line
good line
good line
good line
good line
INIZIO:
...
< 26 lines>
...
FINE:
good line
good line
good line
good line
INIZIO:
...
< 26 lines>
...
FINE:
good line
good line
...
ecc...

or if is possible...

if the code find INIZIO jump directlly to first line after FINE

ohohoho!!!!

After attention to analize the txt i have see the number of lines from INIZIO and FINE are variant and not fixed 26...:-( :sad: :scratch:

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: skip 26 line in txt file

Post by HansV »

Does the file contain the literal text INIZIO: and FINE: ?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: skip 26 line in txt file

Post by sal21 »

HansV wrote:Does the file contain the literal text INIZIO: and FINE: ?
yes, literal text

and all lines between INIZIO e FINE are filled but with variant lengh.

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: skip 26 line in txt file

Post by HansV »

You could use a loop like this:

Code: Select all

  Do While Not EOF(1)
    Line Input #1, riga
    If Left(riga, 7) = "INIZIO:" Then
      ' Skip lines until we encounter "FINE:"
      Do
        Line Input #1, riga
      Loop Until Left(riga, 5) = "FINE:"
    Else
      ' Do something with riga here
      ...
    End If
  Loop
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: skip 26 line in txt file

Post by sal21 »

HansV wrote:You could use a loop like this:

Code: Select all

  Do While Not EOF(1)
    Line Input #1, riga
    If Left(riga, 7) = "INIZIO:" Then
      ' Skip lines until we encounter "FINE:"
      Do
        Line Input #1, riga
      Loop Until Left(riga, 5) = "FINE:"
    Else
      ' Do something with riga here
      ...
    End If
  Loop
:thankyou: :thankyou: :thankyou: :clapping: :clapping: