Computer Science Canada deleting record from binary file |
Author: | hey_joe42 [ Sat Mar 15, 2003 8:53 pm ] | ||
Post subject: | deleting record from binary file | ||
k im trying to have in my program it delete records here is the basics in somewhat pseudocode fashion of what its supposed to do, sorry my pseudocode isn't too good, get name from user read the first field(name field) from record, from file loop exit when eof(file1) compare name and namefield and if they are not the same, write the record to the temp file end loop loop exit when eof(file2) write file2 to file 1 end if now here is the code, for some reason this doesn't work that my problem?
if you can't figure out what is wrong plz feel free to run program attached, but enter your on data first, i suggest sample data or instrustions hit 1 then key in this (mouse,ibm,9.99,2,1,2,111-111,computer,yes : keyboard,ibm,19.99,4,2,4,111-112,computer,no : back) |
Author: | Tony [ Sun Mar 16, 2003 4:07 pm ] |
Post subject: | |
Quote: open : fn2, "temp.bin", write, seek %temporary file to store and move loop exit when eof (fn2) read : fn2, prod %<- file was NOT open for READ put prod.product write : fn, prod end loop thats your problem right there... file was not ment for reading if you also open it for read it works fine. Just one problem... while writing to a binary file, it overwrites it on top, but since it's less in size now, last item remains and you'll have doubles. the solution? you gotta clear the file first. Ether with blank spaces for the last record, OR delete the whole file using File.Delete (filePathName : string) I suppose that just writing blanks will be easier to do and safer since you not gonna lose data if program suddenly crashes. |