newbie wants to read textfile

J

Jurgen Oerlemans

Hello, probably a simple one:
I want to store some settings to a textfile so they are default when the
user re-opens the program.
For this I need to read the text file.
I tried to use the example-code from msdn which I pasted under a
commandbutton :

Imports System ----> Syntax error <-----
Imports System.IO -----> Syntax error <-----

Class Test ----> statement cannot appear within a
method body. End of method assumed
Public Shared Sub Main()
Try
' Create an instance of StreamReader to read from a file.
Dim sr As StreamReader = New
er("TestFile.txt") ---> type Streamreader is not defined <------
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Console.WriteLine(Line)
Loop Until line Is Nothing
sr.Close()
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
End Sub
End Class

I am sure I am doing some basic things very wrong; Can someone help me
reading the textfile?
Any help appreciated.
Jurgen Oerlemans
 
C

Cor Ligthert

Hi Jurgen,

I have answered this in the newsgroup languages.vb where I also wrote to
crosspost next time.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top