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

500 B.C. - 2011
 Originally Posted by techgnome
VB's ' has twice the power of C's / ... that's why it takes two / to equal one '
-tg
-
Sep 6th, 2010, 01:15 PM
#2
Re: Read Multiline txt's
if it's just plain text:
vb Code:
RichTextbox1.text = io.file.readalltext(openfiledialog1.filename)
for rtf use the richtextbox loadfile method
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 11th, 2010, 01:35 PM
#3
Thread Starter
Lively Member
Re: Read Multiline txt's
no, i mean something like that :
vb Code:
Button sub Textbox1.text = ReadMultilineText(RichTextbox1.text,3)'What To Read, Line Number

500 B.C. - 2011
 Originally Posted by techgnome
VB's ' has twice the power of C's / ... that's why it takes two / to equal one '
-tg
-
Oct 11th, 2010, 11:29 PM
#4
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:
Dim lines As String() = IO.File.ReadAllLines("file path here") 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:
Dim line As String Using reader As New IO.StreamReader("file path here") For i = 0 To index line = reader.ReadLine() Next End Using
If that's not what you want, please provide a FULL and CLEAR description of the requirement.
-
Oct 12th, 2010, 07:07 AM
#5
Re: Read Multiline txt's
the rtb control has a lines property. to get the 3rd line you'd use
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 14th, 2010, 08:04 AM
#6
Thread Starter
Lively Member
Re: Read Multiline txt's
Thanks jmcilhinney and .paul.
the codes is exactly what i need .

500 B.C. - 2011
 Originally Posted by techgnome
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|