Solved How can I delete an entry from a text file in Qbasic?

August 20, 2015 at 13:30:53
Specs: Windows 7
There's a project that I'm working on for class. I have to create a phone directory , while using data from a text file. I have to create a function to remove a phone directory entry and am not to sure how to go about that?

See More: How can I delete an entry from a text file in Qbasic?

Report •

August 20, 2015 at 18:27:08
✔ Best Answer
Homework assistance is higly discouraged by this forum, because giving answers defeats the purpose of the student solving a problem using the tools and concepts that the instructor has already supplied them with.
With that said, I'll generalize with what I think I know. QBasic can work with data in two ways: dynamically (in memory, using an array), or by manipulating parts of textfiles on disk. Both have their strengths and wimps. Memory approach requires of course that you have enough memory to load the entire file into an array. (Windows might include implicit "virtual memory" which would include disk support for memory-challenged systems). This approach is assumed to be faster. File (ie: disk) approach allows larger data-volume since the disk is supplying storage, but for that reason is assumed to be slower.
QBasic also suffers from the limitation that it does not have a "delete-element" function for arrays, which most other current languages have. A third option (sorry) is to load the entire text into a long string, then manipulate the string using QB functions, but I believe QB limits strings to 64K but I might be wrong in this.
Ok, that was your introduction and initiation to forum assistance - God help you!
Removal of data in essence: read and write (or leave in place) data up to the point where the deletions is to occur (call this "A" f/e). Then "jump over" the content to be deleted, then, starting where the deletion content ends, append all further material to "A". Simple. With an array, shift all elements "above" the deletion down one element to "pave over" the deleted material.
This does not take into account "indexing" concept, which is a whole nother chapter.

message edited by nbrane

Report •

August 21, 2015 at 01:04:40
Your text file is divided into records, and your task is to delete one record. The normal way that this is done in a database application is not to delete the record and move the remaining data; it is more efficient to blank out the record and then mark it as unused - for example you can use a special character for the first character in the record to indicate this. A later insertion of a new record would then use this free space rather than appending to the end of the file. (As a matter of interest, this is how directory entries in your filesystem work.)

At a later stage, perhaps when closing the program or as part of daily maintenance, you would scan the whole file and consolidate it so that unused records are deleted. The reason for doing this is to maximize program responsiveness as moving the data is a relatively costly operation. It has less of an impact on the user experience if done, en mass, as part of the cleanup when the program is closed or as a maintenance procedure performed when the database is not being used.

Report •

Related Solutions

Ask Question