Computing Staff
  • 8

How Can I Delete An Entry From A Text File In Qbasic?

  • 8

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?

Share

1 Answer

  1. 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.

    • 0