Results 1 to 4 of 4

Thread: [RESOLVED] Find "bookmarks" in a text file...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    177

    Resolved [RESOLVED] Find "bookmarks" in a text file...

    Hi !

    I'm building an application with a text box, where users will write comments and descriptions for each item in the app:s database. For the moment this text box is limited to 100 char:s (bytes) depending on its post length in the file (random access).

    But giving it an other thoughs; Why not let the text in the box be stored in a text file instead, among text from other items, but separated by some certain bookmark. So when approaching an item in the data base, the program calls for this special bookmark in the text file, reading the text and deliver it in to the text box again. The bookmarks will then be stored in the ra-file or even in the data base file itself...

    Then I can keep the box unlimited and its text will be stored more compressed than in a file with certain post length, especially if the text is shorter than 100 char:s - as most often...

    There is at least two question marks.

    One is if a user will change the text somehow, maybe make it shorter or longer. Then the text will be fit in again to the text file, replacing the old piece... Maybe moving the after coming texts forward or backward..

    An other question is how to find a certain bookmark in the text file, reading all text to the next bookmark (or to the end, if it's the last one)

    I think I can write some rough code and make it all works, but I'm sure that someone here have some lot smarter ideas how to manage it all... Am I right...? !

    Thanks in advance

    /Kalle in Sweden

  2. #2
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: Find "bookmarks" in a text file...

    The only way you'd be able to get round users adding more with variable length records would be to read in the whole file, modify the bit you want to change, and then re-writing the whole file. Have you looked into using a database such as MS Access?
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    177

    Re: Find "bookmarks" in a text file...

    Thank you, Arachnid13, for the answer !

    I think I realize that fact, but now - so far - I've been able to manage how to find constructed bookmark in the text file.
    The bookmark is built up by the text file number (if I have to have more than one in order not to make them too big) and the post number in the database file, where the searched text belong. It all beginn with the letters "BM" (as in BookMark).
    A string variable, with defined length (7 char:s) serch through Input in the textfile for this 7 char:s string that's the combination I mentioned, and when finding it, it starts to read from the file into the text box until it finds an other "BM", or the EOF, where it stops reading.

    Yes, it's true, that I have to rewrite the textfile - if changed text in the text box -, but to do that I first copy all its text from start until the bookmark, then the actual bookmark itself and the changed text from the box, and finally the rest of the textfile from the next bookmark - that I've saved in a var. - until the original file ends.

    Then I think I will kill the original textfile and rename the temporary text file to the original name...

    Do you think it seems to be a good method, or are there other, more sofistical and efficient ways...

    /Kalle
    Last edited by Karl-Erik; Aug 21st, 2008 at 12:40 PM.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    177

    Re: Find "bookmarks" in a text file...

    ...
    Even better - I read line by line using Line Input from the file, containing users comments.
    As long as I don't come across the wanted bookmark, I transfer line by line to the temporary file, until my bookmark is red. (Since it is a separate line, I can use Line Input all the way)
    Then I haven't to read the lines twice, both in searching and then with copying.
    Appending the changed text, then the rest of the old file, and it's all done...

    I think I have solved the issue... Haven't I...

    When I have finished clean up the test code and made the tests, then I will present my realtively simple code, since for the moments it is just planning and not so much more...

    Maybe someone get some ideas from it...

    Thanks for the interests...

    /Kalle

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width