Click here to Skip to main content
15,896,453 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: append line number to a text file Pin
Luc Pattyn10-Sep-09 7:12
sitebuilderLuc Pattyn10-Sep-09 7:12 
AnswerRe: append line number to a text file Pin
Hurricane300010-Sep-09 8:12
Hurricane300010-Sep-09 8:12 
GeneralRe: append line number to a text file Pin
cjdc10-Sep-09 9:09
cjdc10-Sep-09 9:09 
GeneralRe: append line number to a text file Pin
Hurricane300010-Sep-09 9:30
Hurricane300010-Sep-09 9:30 
GeneralRe: append line number to a text file [modified] Pin
cjdc10-Sep-09 10:05
cjdc10-Sep-09 10:05 
GeneralRe: append line number to a text file Pin
Hurricane300010-Sep-09 10:33
Hurricane300010-Sep-09 10:33 
GeneralRe: append line number to a text file Pin
cjdc10-Sep-09 10:49
cjdc10-Sep-09 10:49 
AnswerRe: append line number to a text file Pin
Hurricane300011-Sep-09 4:54
Hurricane300011-Sep-09 4:54 
Hi,

Assuming that your problem is ONLY that to add a progressive number for each new line added in the file,your problem is more easy to resolve than you think.
You simply must go in the optical vision of what you want obtain(you have not much fantasy)!
Like already told you by Luc Pattyn, there are several way to obtain that you want.

For your case I suggest you this:

1) You have to read the entire file and count the lines in it contained.
Following code can do this work. At the end, CountLines will contains the number of lines already contained in the file.
Note: If the head of file will contains not numbered lines, you'll have to subtract them from CountLines.

Using sr As StreamReader = New StreamReader(myStream) 'mystream = Path of File
    Dim line As String
    Dim CountLines As Integer = 0
    Do
        line = sr.ReadLine()
        If line = Nothing Then Exit Do
        CountLines = CountLines + 1
    Loop Until line Is Nothing
    sr.Close()
    CountLines = CountLines - 4 'The number 4 indicate eventually first lines to subtract.
End Using
2) To append a new line in the file, you simply have to change your code-line:

sw.WriteLine(DateTime.Now.ToString() + "," + "Reason," + (RichTextBox2.Text)
to
CountLines = CountLines + 1
sw.WriteLine(CountLines.ToString + " , " + DateTime.Now.ToString() + "," + "Reason," + (RichTextBox2.Text)
Note that code I sent you, close the file after read it. Then you have to re-open it.
And also note that the code will have no effect on lines already written, but only on newest.
May be that you'll need to modify the "scope-visibility" of CountLines.

Hope this help you

Ignazio

modified on Friday, September 11, 2009 3:42 PM

GeneralRe: append line number to a text file Solved Pin
cjdc14-Sep-09 0:25
cjdc14-Sep-09 0:25 
Questioncomputer to computer communication event Pin
computbill9-Sep-09 13:09
computbill9-Sep-09 13:09 
AnswerRe: computer to computer communication event Pin
Christian Graus9-Sep-09 13:52
protectorChristian Graus9-Sep-09 13:52 
QuestionClass not registered Pin
RossouwDB9-Sep-09 9:01
RossouwDB9-Sep-09 9:01 
AnswerRe: Class not registered Pin
Christian Graus9-Sep-09 9:22
protectorChristian Graus9-Sep-09 9:22 
GeneralRe: Class not registered Pin
RossouwDB9-Sep-09 10:44
RossouwDB9-Sep-09 10:44 
GeneralRe: Class not registered Pin
Christian Graus9-Sep-09 11:20
protectorChristian Graus9-Sep-09 11:20 
GeneralRe: Class not registered Pin
RossouwDB10-Sep-09 5:01
RossouwDB10-Sep-09 5:01 
GeneralRe: Class not registered Pin
RossouwDB12-Sep-09 5:08
RossouwDB12-Sep-09 5:08 
QuestionSuspendLayout, changing Width property and ResumeLayout(True) Pin
EliottA9-Sep-09 7:46
EliottA9-Sep-09 7:46 
QuestionPossible to pass a string to a Function as name of an array? Pin
Hurricane30009-Sep-09 5:42
Hurricane30009-Sep-09 5:42 
AnswerRe: Possible to pass a string to a Function as name of an array? Pin
Dave Kreskowiak9-Sep-09 6:17
mveDave Kreskowiak9-Sep-09 6:17 
GeneralRe: Possible to pass a string to a Function as name of an array? Pin
Hurricane30009-Sep-09 7:19
Hurricane30009-Sep-09 7:19 
GeneralRe: Possible to pass a string to a Function as name of an array? Pin
Christian Graus9-Sep-09 9:26
protectorChristian Graus9-Sep-09 9:26 
GeneralRe: Possible to pass a string to a Function as name of an array? Pin
Dave Kreskowiak9-Sep-09 11:16
mveDave Kreskowiak9-Sep-09 11:16 
AnswerRe: Possible to pass a string to a Function as name of an array? Pin
dan!sh 9-Sep-09 6:26
professional dan!sh 9-Sep-09 6:26 
GeneralRe: Possible to pass a string to a Function as name of an array? [modified] Pin
Hurricane30009-Sep-09 7:30
Hurricane30009-Sep-09 7:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.