|
-
Jul 31st, 2002, 09:40 PM
#1
Thread Starter
Hyperactive Member
text files
simple i kno, and ive done it before but have forgot 
k.. ive got a text file and im usin my program to write to it, but everytime it writes to it, all the old content is gone! because im using the wrong method, but i dunno whats the right method :s heres what ive got atm:
VB Code:
Dim fso, textfile
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("c:\test.txt") = True Then
Set textfile = fso.OpenTextFile("c:\test.txt", ForWriting)
Else
Set textfile = fso.CreateTextFile("c:\test.txt", True)
End If
help appreciated
-
Jul 31st, 2002, 10:12 PM
#2
PowerPoster
Why are you using FSO? You need to use Appent, not Writing. Why don't you just use Open "File" For Input/Output/Append?
-
Jul 31st, 2002, 10:15 PM
#3
Thread Starter
Hyperactive Member
what else apart from fso can i use? :> + i just tried it with forappend and not alot happens
-
Jul 31st, 2002, 10:47 PM
#4
PowerPoster
VB Code:
'if the file doesn't exist then create it
If Len(Dir("C:\test.txt")) = 0 Then
Open "C:\test.txt" For Output as #1
Print #1, ""
Close #1
'if the file exists the append to it
Else
Open "C:\test.txt" For Append As #1
Print #1, "your data goes here"
Close #1
End If
'read the file back into a variable:
Open "C:\test.txt" For Input As #1
Dim Buffer As String
Buffer = Input$(LOF(1), 1)
Close #1
'Buffer now contains the file
-
Jul 31st, 2002, 10:50 PM
#5
Need-a-life Member
You do not need to test if it exists. Append will create the file if it doesn't exist. On the other hand, if it does exist, it will write at the end of it.
VB Code:
Open "C:\test.txt" For Append As #1
Print #1, "your data goes here"
Close #1
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|