Click here to Skip to main content
15,029,944 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm using objreader.readline to read my config.txt file to pull information, however I can't seem to get it to read the whole line.

My code:
VB
Dim FILE_NAME As String = "C:\Config.txt"

        Dim objReader As New System.IO.StreamReader(FILE_NAME)

        settings.TextBox3.Text = objReader.ReadLine(5)


        objReader.Close()


When I use objreader.readline(1) It will read only the character on line 1. I want it to read the whole line.

Example:

objreader.readline(3)
1. Test
2. Test
3. I want all of this to show in my text box.
4. Test
5. Test

Am I using the right string?
Posted

1 solution

It actually does read the whole line:
http://msdn.microsoft.com/en-us/library/system.io.streamreader.readline.aspx[^].

You actually read the whole line and than extract just one character by its index. No wonder you get one character. Remove this "5". (And don't hard-code anything, for example, indices.)

—SA
   
Comments
CodexHawk 5-May-13 1:41am
   
@Kryukov

I added the 5 to indicate what line I wanted read. It's reading a multi lined config and if I keep it blank it won't specify which line I want to display on the textbox.

For example:
Username.textbox

The textbox.text = objreader.readline(2) would have the information for that said textbox.


Am I doing this wrong? Or is there a better method?
   
No. Read the documentation properly. You cannot indicate line number. Line is read sequentially, and there is no parameters in this method. It simply reads the CURRENT line. Are you getting the idea?
—SA
CodexHawk 5-May-13 1:48am
   
You say it reads the current line, but how does it know which line I want it to read? I want it to read line 5 of my text document. How would I make it more specific?
   
You read lines one by one. How it can be a problem?
—SA
CodexHawk 5-May-13 12:26pm
   
I don't understand what you're saying.. If I put .object.readline it reads the first line of the config text file.. I want it to read the 5th line.
   
Just read the help page I referenced, maybe you can understand it better.
And pat attention that the method has no parameters.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900