SPONSORS:






User Tag List

Results 1 to 3 of 3
  1. #1
    Senior Member
    Join Date
    Mar 2003
    Location
    Portland, OR
    Posts
    121
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    FileSetPointer not working correctly?

    All,

    I am attempting to write some information to the middle of a text file. I am trying to use the FileSetPointer function to navigate to the right spot in the file and write the information out. However I am having issues in that it appears that FileSetPointer doesn't seem to be going to where I'm telling it to go before it writes the information to the file. To simplify things, I made a small text file, 9 lines, with 10 characters per line which when opened in Notepad looks like this :

    1000000000
    2000000000
    3000000000
    4000000000
    5000000000
    6000000000
    7000000000
    8000000000
    9000000000

    Using FileOpen, I open the file in Update mode. Then, using FileSetPointer, I set the pointer to position 50 in the file, which should be the beginning of the sixth line. I then write the value '99' to that position using FileWriteLine. This is what the file looks like after the code is executed:

    1000000000
    2000000000
    3000000000
    4000000000
    5099
    0000
    6000000000
    7000000000
    8000000000
    9000000000

    By my calculations, it seems as though FileSetPointer put the pointer at position 43 before it started writing. Does anyone know if this is correct behaviour? If so, how do I workaround it? Perhaps I am not quite understanding how FileSetPointer works but it seems pretty straightforward.

    Thanks,

    -John



    ------------------

  2. #2
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: FileSetPointer not working correctly?

    The function is working correctly. The first character-position in the file is numbered zero, and there are two characters (the carriage-return and line-feed characters, ascii 13 and 10 respectively) between each line. So the positions at the start of each line in your example are 0, 12, 24, 36, 48, 60, etc.

    ------------------

  3. #3
    Member
    Join Date
    Jun 2001
    Location
    Bedford, MA, USA
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: FileSetPointer not working correctly?

    A simpler way to insert lines into a text file is to:
    1) put the contents of the file into a list
    2) insert your lines
    3) write the file (overiting the original)

    - Jim

    ------------------

 

 

Posting Permissions

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

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 03:42 AM.

Copyright BetaSoft Inc.