Results 1 to 4 of 4

Thread: Opening file for Binary

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    4

    Opening file for Binary

    I want to open a file for Binary:
    Code:
    Open filepath For Binary As #1
    However, I want to also append to the file but not necessarily the end of the file.

    Example:


    01 02 03 04 05 06 0B 0C 0D 0E 0F
    ^

    I want to insert 07 08 09 0A after the 06 but before the 0B.

    I know I can just read the file before I insert the data and then overwrite pretty much the whole file... but what if I am dealing with a large file... it seems rather inefficient. Is there a better way to do this?

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Opening file for Binary

    Hmm maybe using the SendMessage API and adding the text to the file. Then Opening it up?

    Also what is the use of this? Just because once you have done it once you will have to basically manually remove the data so it will work again.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    4

    Re: Opening file for Binary

    Quote Originally Posted by Hell-Lord
    Hmm maybe using the SendMessage API and adding the text to the file. Then Opening it up?

    Also what is the use of this? Just because once you have done it once you will have to basically manually remove the data so it will work again.
    Umm, I don't think so... That would just be ridiculous. This isn't going to be a one time thing, otherwise that would work.

    This is for a freeware game called Apprentice. It's a game that allows you to play Magic the Gathering (collectible card game) online with friends.

    It has a large binary file that contains a large database of all the cards. I studied the format of the binary file to understand how it sorted the data.

    And now I want to add my my own card. However, to do this I would need to add data to the middle of the file.

    (And yes I realize that the new cards I make won't work when I am playing online with someone who doesn't have the same data file as I, so I would have to send them the new data file once I modify it.)

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Opening file for Binary

    You can't just 'insert' data into the middle, or any other part of the file without overwriting the data that comes after it using the standard File I/O.

    You need to open the file, modify the contents and save the new data.

    There is code for for insert & delete data from within the file here:
    http://www.vbforums.com/showthread.p...ghlight=insert

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