Click to See Complete Forum and Search --> : Binary/Random file saving/reading


Muruganvv
October 18th, 2001, 01:12 AM
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

Boumxyz2
October 18th, 2001, 08:25 AM
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