|
-
Dec 19th, 2005, 08:05 PM
#1
Thread Starter
Fanatic Member
-
Dec 19th, 2005, 08:16 PM
#2
Re: How to delete data on .txt file in VB6?
Just write back the lines you want to keep to a new file, delete the old file, and rename the new file to match the old name.
-
Dec 19th, 2005, 08:16 PM
#3
Re: How to delete data on .txt file in VB6?
-
Dec 19th, 2005, 08:24 PM
#4
Thread Starter
Fanatic Member
Re: How to delete data on .txt file in VB6?
what do u mean dglienna? i'll transfer the data line on a old file to a new file?
-
Dec 19th, 2005, 08:39 PM
#5
Thread Starter
Fanatic Member
Re: How to delete data on .txt file in VB6?
because what i want in my project is to read the file in every 5 mins or 30 mins or etc. (depends on options), because that file is always stored new data in every new call. - 1 line is equal to 1 call - so what i want is after i read the new line or new call i delete that line.
-
Dec 19th, 2005, 08:41 PM
#6
Re: How to delete data on .txt file in VB6?
The usual way is to
- read in the file line by line
- write all the lines out to a new, temporary, file except for the line(s) you want to delete
- kill the original file
- rename the temp file with the name of the old file.
-
Dec 19th, 2005, 08:44 PM
#7
Re: How to delete data on .txt file in VB6?
would a database be more useful?
-
Dec 19th, 2005, 08:47 PM
#8
Re: How to delete data on .txt file in VB6?
If you just want to keep new calls in a different file, read them in from the first file, and append them to the old file, and delete the new file. That way, the old fille would contain all the new entries, while the new one (using append if there is more than one possible call in the interval) would contain new calls since last read.
It's easier than I thought. I thought you wanted to delete just one line from a file, when, in fact, you just want to append them to the old file. Have the call center write to the new/temp file, and your main app append the contents to the new file.
This assumes that the call center doesn't have to edit the original information before it gets recorded (but they could still get it from the old file). You'd have to not add those to the new/temp file, or you'd have duplicates.
-
Dec 19th, 2005, 08:55 PM
#9
Thread Starter
Fanatic Member
Re: How to delete data on .txt file in VB6?
actually after i read the line and before i delete it, i store that line into access db. coz now has many calls, and if i didn't delete the old lines in a file, my program will load slow coz my code is to read all the lines and check if that is new call(s).
and access db now contains all old and new data lines or calls.
so what i want to know now is how to delete a (particular) line in a file? tnx...
Last edited by noielen; Dec 19th, 2005 at 09:09 PM.
-
Dec 19th, 2005, 08:58 PM
#10
Re: How to delete data on .txt file in VB6?
If you store the Ticket number in the DB, you could run a SQL query for it, and if it isn't there, add it, but if it is, then allow them to edit/update the information.
That doesn't sound too difficult. Set up the table in Access, and use VB to insert/update it.
-
Dec 19th, 2005, 09:11 PM
#11
Thread Starter
Fanatic Member
Re: How to delete data on .txt file in VB6?
any help here? plz continue...
-
Dec 19th, 2005, 09:15 PM
#12
Re: How to delete data on .txt file in VB6?
You could just load the file into a listbox, then remove the items you don't need, then save it back into the file
-
Dec 19th, 2005, 09:36 PM
#13
Thread Starter
Fanatic Member
Re: How to delete data on .txt file in VB6?
Again! HOW TO DELETE A PARTICULAR LINE IN a FILE? (.txt file)
-
Dec 19th, 2005, 09:50 PM
#14
Re: How to delete data on .txt file in VB6?
Sorry
For an easy question, no one is providing much help eh?
This will remove line 4 from the text file called txtfile.txt, Hope it helps
VB Code:
Private Sub Form_Load()
Dim strdata As String
linenum = 4 'the line you wish to remove
Open App.Path & "\txtfile.txt" For Input As #1
For x = 1 To linenum - 1
If EOF(1) Then Exit Sub
Input #1, txt
strdata = strdata & vbCrLf & txt
Next
If EOF(1) Then Exit Sub
Input #1, txt
While Not EOF(1)
Input #1, txt
strdata = strdata & vbCrLf & txt
Wend
Close #1
Open App.Path & "\txtfile.txt" For Output As #1
Print #1, Mid(strdata, 2, Len(strdata) - 1)
Close #1
End Sub
-
Dec 19th, 2005, 11:08 PM
#15
Re: How to delete data on .txt file in VB6?
That will erase the last line, but I'm not clear on exactly which line you want to delete, and why you wouldn't add all records to one file using append (which writes to the end of the file) and then start fresh with a new file?
-
Dec 19th, 2005, 11:12 PM
#16
Re: How to delete data on .txt file in VB6?
 Originally Posted by dglienna
That will erase the last line
It worked with me, the first loop is to move to just before the line, then i read the line (but i don't add it to the final string) then it moves through the rest of the file. Finally it writes the file.
-
Dec 19th, 2005, 11:17 PM
#17
Re: How to delete data on .txt file in VB6?
OK. I didn't look at it closely, but I think he'd want to search for a string to delete. Who knows the actual line number of a record to delete? Nice attempt at answering anyways.
-
Dec 19th, 2005, 11:25 PM
#18
Re: How to delete data on .txt file in VB6?
-
Dec 19th, 2005, 11:29 PM
#19
Re: How to delete data on .txt file in VB6?
VB Code:
Private Sub Form_Load()
Dim strdata As String
strFindstring = "4"
Open App.Path & "\txtfile.txt" For Input As #1
While Not EOF(1)
Input #1, txt
strdata = strdata & vbCrLf & txt
Wend
Close #1
Replace strdata, strFindstring & vbCrLf, vbNullString
Open App.Path & "\txtfile.txt" For Output As #1
Print #1, Mid(strdata, 2, Len(strdata) - 1)
Close #1
End Sub
-
Dec 19th, 2005, 11:38 PM
#20
Re: How to delete data on .txt file in VB6?
This updates the tkt number every half second, but doesn't append the file, and clear the old one for 5 ticks. It displays the method that I was talking about. There is only up to 5 numbers in the newfile, and a list of them all in the oldfile.
VB Code:
Option Explicit
Dim tkt As Long
Dim ff As Integer
Private Sub Form_Load()
Timer1.Interval = 500
Timer1.Enabled = True
tkt = 1
End Sub
Private Sub Timer1_Timer()
Static ct As Long
ct = ct + 1
tkt = tkt + 1
ff = FreeFile
Open "G:\oldfile.txt" For Append As #ff
Print #ff, tkt
Close #ff
If ct Mod 5 = 0 Then
Call savefile
End If
End Sub
Sub savefile()
Dim str As String
ff = FreeFile
Open "G:\oldfile.txt" For Input As #ff
str = Input(LOF(ff), ff)
Close #ff
str = Left(str, Len(str) - 2) ' trim last linefeed
ff = FreeFile
Open "G:\newfile.txt" For Append As #ff
Print #ff, str
Close #ff
Kill "g:\oldfile.txt"
End Sub
-
Dec 20th, 2005, 12:21 AM
#21
Thread Starter
Fanatic Member
Re: How to delete data on .txt file in VB6?
how about, after read all datas on that file, clean it or erase all the datas. how to do it?
-
Dec 20th, 2005, 12:25 AM
#22
Re: How to delete data on .txt file in VB6?
Do you mean make a new file that is empty or remove it completly (delete it)?
If its to make a new file but empty then use
VB Code:
Open App.Path & "\txtfile.txt" For Output As #1
Close #1
But if its for deleting the file use
VB Code:
Kill App.Path & "\txtfile.txt"
-
Dec 20th, 2005, 12:35 AM
#23
Thread Starter
Fanatic Member
Re: How to delete data on .txt file in VB6?
all lines on that file. erase it! not the "file" to delete but ALL lines under that file.
-
Dec 20th, 2005, 12:38 AM
#24
Re: How to delete data on .txt file in VB6?
When you delete it and create another one then it won't contain anything as you wanted to...
-
Dec 20th, 2005, 12:40 AM
#25
Re: How to delete data on .txt file in VB6?
Step thru my app. You have to change the file locations, unless you have a G: drive. It saves all tkt's in the newfile, but only up to 5 in the oldfile. Then it erases the old file, all in the timer event.
-
Dec 20th, 2005, 02:29 AM
#26
Thread Starter
Fanatic Member
Re: How to delete data on .txt file in VB6?
dglienna, nothings happen!
-
Dec 20th, 2005, 02:34 AM
#27
Thread Starter
Fanatic Member
Re: How to delete data on .txt file in VB6?
add more, how to get the no. of lines in a file? hehehe
-
Dec 20th, 2005, 03:21 AM
#28
Fanatic Member
Re: How to delete data on .txt file in VB6?
oh for god's sakes... manually delete it yourself! lol
peace
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
|