newbie wants to read a 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,

First please, do not "Multipost", send one message to more dotnet newsgroups
"Crosspost", than regulars can see if it is answered, and for the rest we
learn from answers from others. You do that to enter more newsgroups in one
line seperated by a comma.

This is a very nice one which Herfried send last week (I changed it a little
bit)

Dim sr As IO.StreamReader = _
New IO.StreamReader("C:\WINDOWS\WIN.INI")
Do While sr.Peek > -1
Console.WriteLine(sr.ReadLine())
Loop
sr.Close()

I hope this helps,

Cor
....
 
A

Armin Zingler

Jurgen Oerlemans said:
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 :


http://msdn.microsoft.com/library/en-us/vbcn7/html/vbconProgrammingGuidelinesOverview.asp

http://msdn.microsoft.com/library/en-us/vbcn7/html/vbconProgrammingWithObjects.asp

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
J

Jurgen Oerlemans

Thank you!
This set me on the right track.
(will not multipost again)
Jurgen
 

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