|
-
Jan 25th, 2004, 12:08 PM
#1
Thread Starter
Fanatic Member
overwrite values in a file
How do I change t he code in such a way that the number(value) I store in a file is over write ...currently i only know how to write values into the file but dunno how to overwrite.
:
...
...
intcount=intcount +1
Private cmfFile_Click()
Dim intFNum As Integer
intFNum= FreeFile
Open "C:123.txt" For Output As # intFNum
Write #intFNum,intcount;
Close #intFNum
...
the result would be :1,2,3,4...
but i want the number to overwrite to that there is only an Incremented number each time in the file when the button is click...thanks!
-
Jan 25th, 2004, 12:42 PM
#2
Frenzied Member
I use FSO for writing, I would do this:
VB Code:
Dim fso, txtfile
Private sub cmfFile_Click()
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtfile = fso.CreateTextFile("c:\123.txt", True)
txtfile.WriteLine (intcount)
txtfile.Close
End sub
-
Jan 25th, 2004, 12:49 PM
#3
You cannot overwrite the contents when the file is open for sequential access. Two options to solve your problem.
Delete the file before the Open statement and keep your existing code or
Open the file in Binary mode and use Put instead of Write.
VB Code:
intcount=intcount +1
Private cmfFile_Click()
Dim intFNum As Integer
intFNum= FreeFile
Open "C:123.txt" For Binary As # intFNum
Put intFNum, ,intcount
Close #intFNum
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
|