|
-
Dec 10th, 2005, 10:53 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Delete values from text file
Hi all,
I'm writing a chat-type program that sends files to the server and reads them back, a kind of message / email type thing. The messages are stored via FTP using Inet to a server, and then downloaded using the DownloadFromURL function.
The messages will store a main message partin a file on the server and the header will be appended to a central text file. This file will be read on the form_load of the main window, and each line will be output into a list box. That way, the user can select the item from the list box, and perform a range of options such as replying to it and deleting it.
However, the deleting is where I think i'm going to have a problem. I can instruct it to delete the file from the server easily enough, but How am I able to remove a line from within a text file?
I'm saving the files like so:
Code:
Dim FF as integer
FF=freefile()
Open "C:\ArbChat\MessageList.txt" for append as #FF
Write #ff, MessageList
Close #FF
And inputting (real code):
Code:
DownLoadFromURL "http://URLGoesHere/ArbChat/", "MessageList.txt"
Open "C:\ArbChat\MessageList.txt" For Input As #FF
While Not EOF(FF)
Input #FF, MessageTitle
MList.AddItem (MessageTitle)
Wend
Close #FF
Kill ("C:\ArbChat\MessageList.txt")
(MList is the List Box)
So for the delete code, I'm going to need it to open the MessageList.txt file, find a certain line, delete that line, and save the file and then upload it again. Currently only "MessageList" is being written to the file, but eventually it might have more items, such as
Write #FF, MessageLise, Date, Time, UserName
Interestingly enough, I just posted some code for a chap in This thread, and the point that I was stuck with my sample program was exactly the same problem as here. Who'd have thought that I'd encounter the very same problem in my own program moments later!
Thanks for any advice here
-
Dec 10th, 2005, 11:55 AM
#2
Re: Delete values from text file
Read in the file line by line and write every line out to a tmp file except for the line you want to delete. At EOF, kill the input file and rename the tmp file with the name of the input file.
-
Dec 10th, 2005, 12:38 PM
#3
Thread Starter
Addicted Member
Re: Delete values from text file
Hmm, good plan! 
What's the command for renaming files again?
-
Dec 10th, 2005, 12:43 PM
#4
Re: Delete values from text file
Name "C:\temp\aaa.txt" As "C:\temp\bbb.txt"
-
Dec 10th, 2005, 12:47 PM
#5
Thread Starter
Addicted Member
Re: Delete values from text file
Great, thank you
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
|