Hello all,
I want to know how to append my data into text file(C:\). My problem is when I append a data into text file, The data are appended in bottom of the Notepad text file. I want most recent appened data will be added into top of the file.
My code follows,
Dim s As String
s = RsP.Fields("birthday") & vbTab & RsP.Fields("SEX") & vbTab& RsP.Fields("Weddate") & vbTab & RsP.Fields("spouse") & vbTab & RsP.Fields("marriage") & vbTab & RsP.Fields("DATE1")
& vbTab & RsP.Fields("DATE2") & vbTab & RsP.Fields("date3") & vbTab
& RsP.Fields("date4") & vbTab & RsP.Fields("info_6") & vbTab & RsP.Fields("Position") & vbTab & RsP.Fields("deceased")
SetAttr "D:\SQL\AdminLogFILE.txt ", vbNormal
Open "D:\SQL\AdminlogFILE.txt" For Append As #1
Print #1, "* ************* Record Added in Screen: Members-Personal ************* *"
Print #1, "UserId : " & puserName & vbTab & Now
Print #1, ""
Print #1, "NEW RECORD:" & vbTab & s
Close #1
SetAttr "D:\SQL\AdminLogFILE.txt ", vbReadOnly
This is my existing code.
Plzzz...help me

How to display my data in text file-?most recent - should be at the top of Textfile
Bobmmp
If your using Express or 2005 then use the following routine which will append you new content to the top of the file instead of the bottom. Its not the most efficient but does the job.
Sub AppendToTop(ByVal Filename As String, ByVal NewContent As String)
Dim OrigContent As String
OrigContent = My.Computer.FileSystem.ReadAllText(Filename)
My.Computer.FileSystem.WriteAllText(Filename, NewContent & OrigContent, False)
End Sub
PS.
Is this legacy code as the Open and Print methods for writing text to a file I dont see that often in .NET development and I do see a lot in old VB6 code.
Urs Enzler
No, none of the code here will work as these forums are for VB.NET and there are better places to find answers for older versions of VB. Maybe the VB6 newgroups - http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.vb.general.discussion&lang=en&cr=US
Or perhaps the VB6 resource center
http://msdn.microsoft.com/vbrun/
or perhaps www.vbcity.com may be useful places to search for answers on VB6 related questions.
But the general concept still applies that is
1. You are going to read in the contents of the file into a string.
2. Build a new string which contents of you new string contents + Original String Contents from the file
3. Write to new string to the original filename
I would however say that you should download the VB Express product (its free) and start using this as its the new .NET technology, Its Free and its really cool with a lot of new functionality which makes things really easy.
Hopefully this helps and we will see you using VB Express real soon.
Quendi
this will solve your problem:
Imports Microsoft.VisualBasic.FileIO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim str As String
str = FileIO.FileSystem.ReadAllText("c:\test.txt")
str = "0" & vbCrLf & str
FileIO.FileSystem.WriteAllText("c:\test.txt", str, False)
End Sub
End Class
good luck
playpiano
Private
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'will add 'test' at top of textTextBox1.Select(0, 0)
TextBox1.SelectedText =
"test" & vbCrLf End Subjosephsteve
Hello spotty,
I'm Saamy. I like to thank for reply. Yes i'm using VB6.0....Is it work these code in VB6. plz tell me what can i do in vb6.
Bye