Writing in a File

buddyB

Member
Joined
Nov 13, 2003
Messages
10
Location
Eindhoven, NL
Hi,

im writing a program (in vb.net) which keeps a logfile. This logfile is shown in a Richtextbox. In the richtextbox i want to see the last event(logging) on the first line,then newest data first.
Ive tried it with SelectionStart and SelectionLength but it wouldnt work. Actually it is easier for me (my program) if i could write a new event on the first line in the logfile instead of the last line.So in stead of the normal writing 1 then 2 then 3 :
1
2
3

i want to this, write 1 then go up a line and write 2, go up again en write 3:
3
2
1

a piece of my program:

If File.Exists(FilePath & "LogFile" & DateString & ".bms")
FileOpen(2, FilePath & "LogFile" & DateLog & ".bms",OpenMode.Append)
Open LogFile-file

??????? Goto the first line in the logfile????????
WriteLine(2, PandNaam & " " & LogString) write data in the Logfile

FileClose(2) Close the logfile
Else : MsgBox("Cant find LogFile" & DateLog & ".bms.")
End If


Cheers ,

BuddyB
 
Rather than using the legacy VB6 file handling functions you may want to use more of the classes under System.IO. If you create a streamreader based on the file you could just read the entire file into a string array and then use Array.Reverse to put the oldest items at the top.
 
Back
Top