|
-
Aug 1st, 2004, 09:36 AM
#1
Thread Starter
Fanatic Member
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:
streamer.ReadLine()
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.
-
Aug 1st, 2004, 10:58 AM
#2
Frenzied Member
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.
-
Aug 1st, 2004, 02:28 PM
#3
Thread Starter
Fanatic Member
Just simply...
VB Code:
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
Do Until EOF(1)
LineIn = LineInput(1)
txtText.Text = txtText.Text & LineIn & vbCrLf
Loop
txtText.Text = txtText.Text.TrimEnd(vbCrLf.ToCharArray)
txtText.Select(0, 0)
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!
-
Aug 1st, 2004, 02:29 PM
#4
Thread Starter
Fanatic Member
oh, and LineIn is just declared as a String
-
Aug 1st, 2004, 02:51 PM
#5
Frenzied Member
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:
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
LineInput(1) ' Possible exception
Do Until EOF(1)
LineIn = LineInput(1)
Or maybe
VB Code:
Dim isFirstLine as Boolean = True
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
Do Until EOF(1)
LineIn = LineInput(1)
If Not isFirstLine Then
txtText.Text = txtText.Text & LineIn & vbCrLf
End If
isFirstLine = False
Or something like that. BTW, I did not check this in the IDE.
-
Aug 1st, 2004, 04:24 PM
#6
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|