Results 1 to 6 of 6

Thread: [RESOLVED] Read Multiline txt's

  1. #1

    Thread Starter
    Lively Member TETYYS's Avatar
    Join Date
    May 2010
    Location
    Spam Land
    Posts
    116

    Resolved [RESOLVED] Read Multiline txt's

    I Know How To Save Multi Line Txt's
    vb.net Code:
    1. System.IO.File.WriteAllText(OpenFileDialog1, RichTextbox1.text & vbCrLf & RichTextbox1.text & vbCrLf & Label1.text)
    But How To Get/Read It Like
    vb.net Code:
    1. RichTextbox1.text = 'Some Multiline Read Code
    Last edited by TETYYS; Sep 6th, 2010 at 01:10 PM.

    500 B.C. - 2011
    Quote Originally Posted by techgnome View Post
    VB's ' has twice the power of C's / ... that's why it takes two / to equal one '

    -tg

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

    Re: Read Multiline txt's

    if it's just plain text:

    vb Code:
    1. RichTextbox1.text = io.file.readalltext(openfiledialog1.filename)

    for rtf use the richtextbox loadfile method

  3. #3

    Thread Starter
    Lively Member TETYYS's Avatar
    Join Date
    May 2010
    Location
    Spam Land
    Posts
    116

    Re: Read Multiline txt's

    no, i mean something like that :
    vb Code:
    1. Button sub
    2. Textbox1.text = ReadMultilineText(RichTextbox1.text,3)'What To Read, Line Number

    500 B.C. - 2011
    Quote Originally Posted by techgnome View Post
    VB's ' has twice the power of C's / ... that's why it takes two / to equal one '

    -tg

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Read Multiline txt's

    Your question doesn't make a lot of sense. If you want to read the entire file then you have already been shown. If you only want to read a specific line then it would probably have been a good idea to say that somewhere.

    A multi-line text file is just a text file. The line breaks are characters too so, as far as the file is concerned, they are just like any other characters. .NET can read text files line by line by reading characters until a line break is detected. If you want to read one specific line, unless you know the exact location that that line starts, you have no choice but to read everything in the file up to and including that line.

    If the file is relatively small then the simplest way to get a single line is to just read the lot into an array and then pick out the line you want by index, e.g.
    vb.net Code:
    1. Dim lines As String() = IO.File.ReadAllLines("file path here")
    2. Dim line As String = lines(index)
    That's a bit inefficient though, because you will likely end up reading data after the line you want that you don't have to. That's not a big deal for small files but for large files it's a concern. In that case, you should read and discard the lines before the one you want, e.g.
    vb.net Code:
    1. Dim line As String
    2.  
    3. Using reader As New IO.StreamReader("file path here")
    4.     For i = 0 To index
    5.         line = reader.ReadLine()
    6.     Next
    7. End Using
    If that's not what you want, please provide a FULL and CLEAR description of the requirement.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: Read Multiline txt's

    the rtb control has a lines property. to get the 3rd line you'd use

    vb Code:
    1. [rtbname].lines(2)

  6. #6

    Thread Starter
    Lively Member TETYYS's Avatar
    Join Date
    May 2010
    Location
    Spam Land
    Posts
    116

    Resolved Re: Read Multiline txt's

    Thanks jmcilhinney and .paul.

    the codes is exactly what i need .

    500 B.C. - 2011
    Quote Originally Posted by techgnome View Post
    VB's ' has twice the power of C's / ... that's why it takes two / to equal one '

    -tg

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