Click here to Skip to main content
15,922,007 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: How we recognition Time Between 2 Time??? Pin
Christian Graus9-Sep-09 18:54
protectorChristian Graus9-Sep-09 18:54 
AnswerRe: How we recognition Time Between 2 Time??? Pin
εїзεїзεїз10-Sep-09 6:47
εїзεїзεїз10-Sep-09 6:47 
Questionnumbrix puzzle Pin
rbjanaki9-Sep-09 15:21
rbjanaki9-Sep-09 15:21 
AnswerRe: numbrix puzzle Pin
Luc Pattyn9-Sep-09 15:25
sitebuilderLuc Pattyn9-Sep-09 15:25 
AnswerRe: numbrix puzzle Pin
Christian Graus9-Sep-09 16:07
protectorChristian Graus9-Sep-09 16:07 
AnswerRe: numbrix puzzle Pin
rbjanaki9-Sep-09 16:15
rbjanaki9-Sep-09 16:15 
GeneralRe: numbrix puzzle Pin
Christian Graus9-Sep-09 16:42
protectorChristian Graus9-Sep-09 16:42 
GeneralRe: numbrix puzzle Pin
εїзεїзεїз10-Sep-09 7:19
εїзεїзεїз10-Sep-09 7:19 
GeneralRe: numbrix puzzle Pin
rbjanaki10-Sep-09 8:06
rbjanaki10-Sep-09 8:06 
Questionappend line number to a text file [SOLVED] [modified] Pin
cjdc9-Sep-09 13:53
cjdc9-Sep-09 13:53 
AnswerRe: append line number to a text file Pin
Christian Graus9-Sep-09 14:20
protectorChristian Graus9-Sep-09 14:20 
GeneralRe: append line number to a text file Pin
cjdc9-Sep-09 14:29
cjdc9-Sep-09 14:29 
GeneralRe: append line number to a text file Pin
Christian Graus9-Sep-09 14:48
protectorChristian Graus9-Sep-09 14:48 
GeneralRe: append line number to a text file Pin
cjdc9-Sep-09 14:57
cjdc9-Sep-09 14:57 
GeneralRe: append line number to a text file Pin
Christian Graus9-Sep-09 15:05
protectorChristian Graus9-Sep-09 15:05 
AnswerRe: append line number to a text file Pin
Luc Pattyn9-Sep-09 15:21
sitebuilderLuc Pattyn9-Sep-09 15:21 
GeneralRe: append line number to a text file Pin
cjdc10-Sep-09 7:03
cjdc10-Sep-09 7:03 
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

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.