Results 1 to 6 of 6

Thread: Ignore first line of file [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575

    Ignore first line of file [RESOLVED]

    Hey,
    I'm im a kind of sticky situation here...

    I know how I would skip to the second line of a file using StreamReader, i would just do:

    VB Code:
    1. streamer.ReadLine()
    2. Dim strLine as String = streamer.ReadLine()

    So basically that skips the first line and puts the second line into the string strLine

    But... I've gone and stupidly used FileOpen instead, and have already implemented this throughout the entire code so I can't switch back now! Aggh!

    If I were to rewrite this prog I would definitely stay away from FileOpen, but i used it because it was quick and easy to read through the file fast.

    So... is there the same method as that, that I shown for the streamreader with FileOpen instead? So I can just ignore the first line and read the rest instead.

    Thanks a bunch!
    Last edited by LITHIA; Aug 1st, 2004 at 04:25 PM.

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    How are you currently reading the file? Can you post some code? Might have to do different things if you're opening in binary or whatever.

  3. #3

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    Just simply...
    VB Code:
    1. FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
    2. Do Until EOF(1)
    3.             LineIn = LineInput(1)
    4.             txtText.Text = txtText.Text & LineIn & vbCrLf
    5.         Loop
    6. txtText.Text = txtText.Text.TrimEnd(vbCrLf.ToCharArray)
    7.         txtText.Select(0, 0)
    8.         FileClose(1)
    The trim at the end gets rid of the extra VbCrLf that I don't want.

    That's how i read the file and put the contents into the text file. Now, i want exactly the same as that, except to miss out the first line of the file and start adding the contents into the textbox from the second line.
    I store some special data in the first line with the writing procedure of my program which can only get read by my program. It's used for settings so I don't want it being put into the textbox after its read.
    Thanks!

  4. #4

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    oh, and LineIn is just declared as a String

  5. #5
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    ok. I guess you could do a couple things, but you're going to have to look out for error checking. Just ideas here, no gospel.

    One, you could do this
    VB Code:
    1. FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
    2. LineInput(1) ' Possible exception
    3. Do Until EOF(1)
    4.             LineIn = LineInput(1)

    Or maybe
    VB Code:
    1. Dim isFirstLine as Boolean = True
    2. FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
    3. Do Until EOF(1)
    4.             LineIn = LineInput(1)
    5.  
    6.             If Not isFirstLine Then
    7.                 txtText.Text = txtText.Text & LineIn & vbCrLf
    8.             End If
    9.  
    10.             isFirstLine = False

    Or something like that. BTW, I did not check this in the IDE.

  6. #6

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    hehe thanks mike! the first one did the trick

    i'm sure the second one would have too, but the first was a lot easier and was a lot more similiar to the streamer method above.

    Thanks! Resolvdyed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width