Click here to Skip to main content
15,568,971 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:
Dim FILE_NAME As String = "C:\Config.txt"

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

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


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


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?

1 solution

It actually does read the whole line:[^].

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.)

Share this answer
CodexHawk 5-May-13 1:41am    

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:

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?
Sergey Alexandrovich Kryukov 5-May-13 1:45am    
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?
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?
Sergey Alexandrovich Kryukov 5-May-13 2:59am    
You read lines one by one. How it can be a problem?
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.

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