VB.NET - Readline and sequential file - Asked By teocyoa taidslfs on 04-Nov-05 10:01 PM

Could someone help me please How do I read a particular line from a file and save it a variable.

you can use streamreader - Asked By Venkat K on 04-Nov-05 11:24 PM

to read a file. see this
Public Function GetFileContents(ByVal FullPath As String, _
       Optional ByRef ErrInfo As String = "") As String

        Dim strContents As String
        Dim objReader As StreamReader
        Try

            objReader = New StreamReader(FullPath)
            strContents = objReader.ReadToEnd()
            objReader.Close()
            Return strContents
        Catch Ex As Exception
            ErrInfo = Ex.Message
        End Try
    End Function

Readline - Asked By Sunitha Nambari on 04-Nov-05 11:56 PM

hi,

Imports System.IO

Dim sr as New StreamReader("C:\Suneetha\eggheadcafe.txt")
Dim line as String = sr.ReadLine()
Do While Not line is Nothing
Response.Write(line & "<br>")
line = sr.ReadLine()
Loop

Let me know if it has helped....

Regards,
Suneetha

StreamReader ( Readline) - Asked By Sameer Jain on 05-Nov-05 01:23 AM

See the examples here
Sub ReadCalibration()
' Determine the path of the file from the application itself
Dim calfile As String = Application.StartupPath + "\cal.txt"
If File.Exists(calfile) Then '
Illegal whitespace in constant
Dim tr As New StreamReader(calfile)
Dim num As String = tr.ReadLine()
Calibration = Convert.ToInt32(num)
tr.Close()
End If
End Sub 'ReadCalibration

Sub WriteCalibration()
Dim calfile As String = Application.StartupPath + "\cal.txt"
Dim tw As New StreamWriter(calfile) '
tw.Flush() ' Write out the calibration value
tw.WriteLine(Calibration.ToString())
tw.Close()
End Sub 'WriteCalibration

http://www.vbdotnetheaven.com/Code/Jun2003/2090.asp

http://www.builderau.com.au/program/windows/print.htm?TYPE=story&AT=20267367-39024644t-20000994c

http://www.builderau.com.au/program/windows/0,39024644,20267367,00.htm

thanks
What i did to get to work - Asked By teocyoa taidslfs on 05-Nov-05 07:38 PM
Form1
Dim strfilename As String = strsavedId & ".txt"
        Dim objStreamWriter As System.IO.StreamWriter
objStreamWriter = System.IO.File.AppendText(strfilename)
            objStreamWriter.WriteLine(strsavedId)
            objStreamWriter.WriteLine(strSavedPass)
            objStreamWriter.WriteLine(strFname)
            objStreamWriter.WriteLine(strLastName)
            objStreamWriter.WriteLine(strBusiness)
            objStreamWriter.WriteLine(strCountry)
            objStreamWriter.WriteLine(strCity)
            objStreamWriter.WriteLine(strAddress)
            objStreamWriter.WriteLine(strPhone)
            objStreamWriter.Close()

And then to read 
Form2

Dim objSReader As System.IO.StreamReader
If System.IO.File.Exists(strUserId & ".txt") Then
            objSReader = System.IO.File.OpenText(strUserId & ".txt")
            strsavedId = objSReader.ReadLine()
            strSavedPass = objSReader.ReadLine()
            strFname = objSReader.ReadLine()
            strLastName = objSReader.ReadLine()
            strBusiness = objSReader.ReadLine()
            strCountry = objSReader.ReadLine()
            strCity = objSReader.ReadLine()
            strAddress = objSReader.ReadLine()
            strPhone = objSReader.ReadLine()
            objSReader.Close()
End if of course

This is what I did it appears to work but i haven't fully tested it ill try ur suggests too 
thanks so much for the help