Results 1 to 5 of 5

Thread: [RESOLVED] Read Line Number X

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    England
    Posts
    79

    Resolved [RESOLVED] Read Line Number X

    Ive got an array of numbers, and I need to go through it, and grab information from lines of a text file, that correspond to the numbers in this array...

    EG:

    Array(1,5,10,12)

    I want to read in order:

    Line 1
    Line 5
    Line 10
    Line 12

    Now I can do the loop bit, but I am unsure on how to go to Line X and read all the information from that line. Anyone able to help me out?

    Cheers

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Read Line Number X

    I think there's no alternative but using StreamReader.ReadLine method?

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    England
    Posts
    79

    Re: Read Line Number X

    Yes, but how do I get that to read line number X ?

    Can you post an example for me please?

  4. #4
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Read Line Number X

    VB Code:
    1. Public Function GotoLine(ByVal filename As String, ByVal line As Int32) As String
    2.  
    3.         Dim fs As New StreamReader(filename)
    4.         Dim aLine As String = String.Empty
    5.         Dim counter As Int32 = 0
    6.         Try
    7.             Do
    8.  
    9.                 aLine = fs.ReadLine
    10.                 counter += 1
    11.                 If counter = line Then Exit Do
    12.             Loop Until aLine Is Nothing
    13.  
    14.         Catch ex As Exception
    15.             ''MessageBox.Show(ex.Message)
    16.         End Try
    17.         fs.Close()
    18.         Return aLine
    19.     End Function
    "The dark side clouds everything. Impossible to see the future is."

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    England
    Posts
    79

    Re: Read Line Number X

    Sorted. Didn't think about using a loop, having a blonde day...

    Cheers

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