CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2001
    Location
    S. India
    Posts
    1

    Binary/Random file saving/reading

    Hi,
    What is the different between Random Access File operations & Binary Access File operations in VB.

    In my application there are many different types of UDT.
    for example
    '-------------------------------------
    'Structure for object position
    public Type ObjPos
    Left as Integer
    Top as Integer
    Height as Integer
    Width as Integer
    End Type

    'Structure for object font
    public Type ObjFont
    FontName as string
    FontStyle as Integer
    FontSize as Integer
    FontColor as Long ' ColorConstants
    End Type

    'Structure for common obj properties
    public Type CommonObjProperties
    uobjPos as ObjPos
    uFont as ObjFont
    strCommonItem as string
    nTableID as Integer
    bBorder as Boolean
    iAlignment as Integer
    nBackgroundColor as Long
    End Type
    ''' and many more big structures also there
    '-------------------------------------




    I have to write each of this structure to a file many times.
    Because the record length is different for the three UDT, how I can give the 'len' in the file open command in random mode. If I give the length of the largest record.... the file size will becomes very large. If I did not give the len, it will not reading the file after writing.

    My doubt is here, can I use the binary mode for opening the file. In binary mode the len part is not needed in the file open command.

    Is there any document available, which describes the "File Open in binary mode".

    Thanks in advance.
    Murugan



    Murugan V V

  2. #2
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: Binary/Random file saving/reading

    You could add a field to your object which would actually be a fixed field ( Like let's say an integer ) where you can actually put the Length of the record you just wrote. So that way you just seek out that field, load it and then replace the File pointer and then do get the record with the lenght pointed by that field.

    Plcae that field at the start of the record so you always know that the first 2 bytes of the object is the lenght of your object. It will work unless VB compiler is "OPTIMIZING" memory space and place the field somewhere so the object takes less space. Ususally this is not done because we expect the programmer to be intelligent and respect memory boundaries..


    Integers are fixed usually 2 bytes.

    I hope it helps

    Nic

    Nicolas Bohemier

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

Featured