Results 1 to 4 of 4

Thread: How to read text file line by line?

Hybrid View

  1. #1
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: How to read text file line by line?

    try this:

    vb Code:
    1. dim lblCounter as integer = 1
    2.  
    3. Do while srFileReader.peek <> -1
    4.     'this will ouput text to label1, label2...etc
    5.     me.controls("Label" & lblCounter.tostring).text = sInputLine
    6.     lblCounter += 1
    7.     System.Console.WriteLine(sInputLine)
    8.     sInputLine = srFileReader.ReadLine()
    9.  
    10. Loop
    Last edited by .paul.; Sep 19th, 2010 at 06:35 PM.

  2. #2
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    Re: How to read text file line by line?

    @ paul you might want to check if the form actually contains a label of that name just in case. Also, using/endusing for streamreaders are a lot easier

    vb Code:
    1. Using sRead As New IO.StreamReader("D:\Users\Arben\Desktop\SerieA.txt")
    2.       Dim thisLine as string = ""
    3.       Dim nLabel as Integer = 0
    4.       Do Until sRead.EndOfStream
    5.           thisLine = sRead.ReadLine
    6.           if Me.Controls.ContainsKey("Label" & nLabel) then
    7.                Me.Controls("Label" & nLabel).Text = thisLine
    8.           End if
    9.           nLabel += 1
    10.        Loop
    11. End using

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width