VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Reading Multi-Line data from a File seperately in .NET Posted by vrao_n on 13 Dec 2004 at 2:58 PM
Hi,

I am trying to read data from a file by using StreamReader. When I use ReadLine statement it is allowing me to read a line only for once. But I need to read each line of file seperately and need to do some validations on that data.

Anybody plz help in resolving this...

Thanks in advance.

regards,
Venkat
Report
Re: Reading Multi-Line data from a File seperately in .NET Posted by kainsworth on 14 Dec 2004 at 5:22 AM
Hi

You can test each line at a time with code like this:
Dim strFileName As String = Directory.GetCurrentDirectory() & "\MyFile.txt"  ' pointer to file
Dim txtFile As New FileStream(strFileName, FileMode.Open, FileAccess.Read)
    Dim FileStream As New StreamReader(txtFile)
 Dim strCheck As String  ' Temp string for ReadLine

 Do Until FileStream.Peek = -1 ' Read until end of file
 strCheck = FileStream.ReadLine ' Next line into string
'  Test
  If strCheck <or part of it> = <some validation check> Then <take some action>
 Loop


Did I understand your question correctly? If not, please do post a follow up and I'll try harder

Ged
Report
Re: Reading Multi-Line data from a File seperately in .NET Posted by vrao_n on 15 Dec 2004 at 2:36 PM
Hi,

You understand my need. But when I try to do so (with the code given), for first line it is reading data but from next line it is not.

Thanks for your help, plz help me on this issue too.

regards,
Venkat.

: Hi
:
: You can test each line at a time with code like this:
:
: Dim strFileName As String = Directory.GetCurrentDirectory() & "\MyFile.txt"  ' pointer to file
: Dim txtFile As New FileStream(strFileName, FileMode.Open, FileAccess.Read)
:     Dim FileStream As New StreamReader(txtFile)
:  Dim strCheck As String  ' Temp string for ReadLine
: 
:  Do Until FileStream.Peek = -1 ' Read until end of file
:  strCheck = FileStream.ReadLine ' Next line into string
: '  Test
:   If strCheck <or part of it> = <some validation check> Then <take some action>
:  Loop
: 

:
: Did I understand your question correctly? If not, please do post a follow up and I'll try harder
:
: Ged
:

Report
Re: Reading Multi-Line data from a File seperately in .NET Posted by vrao_n on 15 Dec 2004 at 2:51 PM
I am Sorry, it is the problem with file. There are blank rows in file, so it is giving an error.

Thanks for valuable help ... Ged.

: Hi,
:
: You understand my need. But when I try to do so (with the code given), for first line it is reading data but from next line it is not.
:
: Thanks for your help, plz help me on this issue too.
:
: regards,
: Venkat.
:
: : Hi
: :
: : You can test each line at a time with code like this:
: :
: : Dim strFileName As String = Directory.GetCurrentDirectory() & "\MyFile.txt"  ' pointer to file
: : Dim txtFile As New FileStream(strFileName, FileMode.Open, FileAccess.Read)
: :     Dim FileStream As New StreamReader(txtFile)
: :  Dim strCheck As String  ' Temp string for ReadLine
: : 
: :  Do Until FileStream.Peek = -1 ' Read until end of file
: :  strCheck = FileStream.ReadLine ' Next line into string
: : '  Test
: :   If strCheck <or part of it> = <some validation check> Then <take some action>
: :  Loop
: : 

: :
: : Did I understand your question correctly? If not, please do post a follow up and I'll try harder
: :
: : Ged
: :
:
:

Report
Re: Reading Multi-Line data from a File seperately in .NET Posted by kainsworth on 16 Dec 2004 at 3:33 AM
Did you resolve the blank lines problem? If not, then something like this should do the trick:
'  Replace
If strCheck <or part of it> = <some validation check> Then <take some action>
' with
If strCheck <> "" AND strCheck = <some validation check> Then <take some action>


Ged

================================================================



: I am Sorry, it is the problem with file. There are blank rows in file, so it is giving an error.
:
: Thanks for valuable help ... Ged.
:
: : Hi,
: :
: : You understand my need. But when I try to do so (with the code given), for first line it is reading data but from next line it is not.
: :
: : Thanks for your help, plz help me on this issue too.
: :
: : regards,
: : Venkat.
: :
: : : Hi
: : :
: : : You can test each line at a time with code like this:
: : :
: : : Dim strFileName As String = Directory.GetCurrentDirectory() & "\MyFile.txt"  ' pointer to file
: : : Dim txtFile As New FileStream(strFileName, FileMode.Open, FileAccess.Read)
: : :     Dim FileStream As New StreamReader(txtFile)
: : :  Dim strCheck As String  ' Temp string for ReadLine
: : : 
: : :  Do Until FileStream.Peek = -1 ' Read until end of file
: : :  strCheck = FileStream.ReadLine ' Next line into string
: : : '  Test
: : :   If strCheck <or part of it> = <some validation check> Then <take some action>
: : :  Loop
: : : 

: : :
: : : Did I understand your question correctly? If not, please do post a follow up and I'll try harder
: : :
: : : Ged
: : :
: :
: :
:
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.