Code:
Dim lineno As Integer = 1
Dim r As New IO.StreamReader("C:\SuperPad\LineNumbers.txt")
While (r.Peek() > -1)
ListBox1.Items.Add(lineno.ToString & " " & r.ReadLine)
lineno = lineno + 1
End While : r.Close()
Hello.
Bye.
Hi.
The listbox will say:
1 Hello
2 Bye
3 Hi
4
5
6 Hello
7 Bye
8 Hi
And so on, for at least 3 times. The following is the code that saves the RichTextBox lines to a file (yes, I'm reading each line of a RichTextBox):
[CODE]
Dim charIndex As String
Dim lineIndex As String
Dim line As String
IO.Directory.CreateDirectory("C:\SuperPad")
Dim w As New IO.StreamWriter("C:\SuperPad\LineNumbers.txt")
Dim i As Integer
Dim length As Integer = CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Lines.Length
charIndex = CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Text.LastIndexOf(lastchar)
lineIndex = CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).GetLineFromCharIndex(charIndex)
line = CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Text.Substring(lineIndex)
For i = 0 To length - 1
w.WriteLine(line)
Next
w.Close()
[CODE\]
"lastchar" is the last typed character of the richtextbox. (in richtextbox keydown event)
Thanks for your time in advance,
Bill W.