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).
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
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?
4) Are you trying to learn how to program, or have the program written for you?
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.