Hello to everyone, i have a project which base on text file. and i already know how to view the text file using a listbox, what i want to know is on how to delete a specific row in text file.. thanks;)

post an example of the textfile, and we can go from there. The concept is fairly simple, however. You open the text file, and while you are reading in all the contents, compare each line with whatever you are looking for (say, the persons social security number), and then if they do not match, add that line to a string (or to another, temp file), and if they DO match, simply don't add it to the new file (or the string variable).

2005/11/11 17:36:13, Event:Access, Door:entry, Card No.:1234, Description:333
2005/11/11 17:36:17, Event:Access, Door:entry, Card No.:1234, Description:333
2005/11/11 17:36:20, Event:Access, Door:entry, Card No.:2222, Description:222
2005/11/11 17:36:26, Event:Access, Door:entry, Card No.:2222, Description:222

hello sir this is the sample of the text file... would you please give me a code which can i delete a specific row... thanks Comatose

How are you going to decide which row? The user has a listbox, and the listbox has all this same information? Will they be deleting the row date, time, cardno or description?

thanks for your response.. my project is to create a time and attendance using a reader which the reader createss a textlog
like this

2005/11/11 13:32:45, Event:PIN Error, Door:entry, Description:201:44000
2005/11/11 13:39:58, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 13:39:59, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 13:40:03, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 13:40:26, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 13:40:28, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 13:48:58, Event:Card No. Error, Door:entry, Description:66:19157
2005/11/11 13:48:58, Event:PIN Error, Door:entry, Description:66:19157
2005/11/11 14:24:03, Event:PIN Error, Door:entry
2005/11/11 15:19:59, Event:Card No. Error, Door:entry, Description:66:19157
2005/11/11 15:20:03, Event:PIN Error, Door:entry, Description:66:19157
2005/11/11 15:20:05, Event:PIN Error, Door:entry, Description:66:19157
2005/11/11 15:20:50, Event:Door Group Error, Door:entry, Card No.:2229, Description:66:19157
2005/11/11 17:36:05, Event:Door Group Error, Door:entry, Card No.:2229, Description:66:19157
2005/11/11 17:36:13, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:36:17, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:36:20, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:36:26, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:36:41, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:36:45, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:36:51, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:37:19, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:37:36, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:37:45, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:37:54, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:38:11, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:38:20, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:39:40, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:41:04, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:43:51, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:50:58, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:51:11, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:51:44, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:52:31, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:52:47, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:52:55, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 17:53:31, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2005/11/11 18:32:48, Event:Password Error, Door:entry, Card No.:1240
2005/11/11 18:35:32, Event:Access, Door:entry, Card No.:2271, Description:266:55250
2005/11/11 18:35:38, Event:Access, Door:entry, Card No.:2271, Description:266:55250
2005/11/11 18:36:01, Event:Access, Door:entry, Card No.:2271, Description:266:55250
2005/11/11 18:55:41, Event:Access, Door:entry, Card No.:2271, Description:266:55250
2005/11/11 18:57:41, Event:Access, Door:entry, Card No.:2271, Description:266:55250
2005/11/11 19:06:25, Event:Access, Door:entry, Card No.:2345, Description:266:55732

when i open this file in list box us you notice there is some text row that is diff. from the others. that specific row i want to delete because when i save this file in access if there is some row that are diff to the other is creates a error.. thanks

Can you define which ones should be removed? Anything that is not:
2005/11/11 17:50:58, Event:Access, Door:entry, Card No.:2345, Description:266:55732
Right?

yes sir, anything that not match the format

2005/11/11 17:50:58, Event:Access, Door:entry, Card No.:2345, Description:266:55732

thanks

Read each line
If it contains "Event:Access, Door:entry, Card No.", write it to the file
If not, don't
If not at end-of-file, go back to read the next line

thanks to your reply,but sir a want a sample code..thanks

Please sir, first answer these questions:
1) do you know how to open a file?
2) Do you know how to read the file one line at a time?
3) Do you know how to check if a line (string) contains specific substring?

And finally
4) Are you trying to learn how to program, or have the program written for you?

yes i already know how to open a file, all i want to know is to delete a specific row in the text file..

InFile = FreeFile
olist.Clear
sFile = txtFile.Text

Open sFile For Input As InFile
While Not EOF(InFile)
Line Input #InFile, sTemp
olist.AddItem sTemp
Wend
Close InFile

i'm using listbox to open the text file..thanks to your response

OK, now we know where to go. Look into the instr() function. It will look thru string A to see if string B is contained in A. Using the code you posted:

InFile = FreeFile
sFile = txtFile.Text

Open sFile For Input As InFile
'' Open the output file to hold the edited data

While Not EOF(InFile)
    Line Input #InFile, sTemp
    '' here use the instr() function to see if you should output 
    '' the line to a second file.  If so, output the line.
Wend
Close InFile
Close OutFile
This article has been dead for over six months. Start a new discussion instead.