file i/o, random access? 
Author Message
 file i/o, random access?

How does do random file i/o using the api?

After opening the file with CreateFile() and before closing it, can one both
read and write to any point in the file?

How does one move the file pointer around?  Can one read and write anywhere
in the file?

Is the overlapped structure necessary?  Or is that only related to
synchronization?

I'd love to see any examples of how to use readfile() and writeFile() to do
this.

Thanks very much.



Tue, 19 Mar 2002 03:00:00 GMT  
 file i/o, random access?

The file pointer is specified in the overlapped structure?  Is that correct?
If so, which members of the type must one use for this?

Thanks.



Quote:
> How does do random file i/o using the api?

> After opening the file with CreateFile() and before closing it, can one
both
> read and write to any point in the file?

> How does one move the file pointer around?  Can one read and write
anywhere
> in the file?

> Is the overlapped structure necessary?  Or is that only related to
> synchronization?

> I'd love to see any examples of how to use readfile() and writeFile() to
do
> this.

> Thanks very much.



Tue, 19 Mar 2002 03:00:00 GMT  
 file i/o, random access?
Seek()?  Is that how the file pointer is moved about?

Thanks again.



Fri, 22 Mar 2002 03:00:00 GMT  
 file i/o, random access?
SetFilePointer() is it?  Finally found a trail.

There must be a common confusion about the VB Seek() function.  There is a
Seek() listed in the SDK, but it has no articles (in the msdn library).  It
sounds like it does what SetFilePointer() does.

Quote:
> Seek()?  Is that how the file pointer is moved about?

> Thanks again.



Fri, 22 Mar 2002 03:00:00 GMT  
 file i/o, random access?
It looks like, I've found with experimentation, that VB's own I/O methods
will allow real random acces to a file.
Still haven't exactly figured out the API for doing this, which no doubt
VB's functions are based on.

The following is what I've found:

VB's Random mode creates a proprietary VB formatted file (using types as
records, their members as fields - much less flexible that the Fields
definition statement in Dos Basic flavours) and sequential access doesn't
allow reading and writing to a file in a single session.  This can be handy,
but if you want complete control over the file's format, it's pretty
useless.

Real random access is accomplished in Visual Basic with Binary mode combined
with VB's
Seek() function.  The Seek() function is used to move the pointer around.
If opened just for INPUT, Seek() can also move the file pointer anywhere, so
one has basically random access to read any point in the file.

If opened for Binary, the file can be read or written to at any point
without closing to change mode from input to output or vice-versa.  Put(),
Input(), and Seek() combined allow this in Binary access mode.

To read, first set the file pointer position with SEEK(), then use input and
pass it
a specified number of bytes to read.  One also has to use a slightly unusual
syntax for Input() in this situation.  For example:

    Seek #1, NextCharPos   ' Set position.
    MyChar = Input(1, #1)   ' Read one character.

To write to the file, set the file pointer with Seek(), then use Put() to
write to the file.  If using Seek(), don't specify the recLength parameter
of Put().  The documentation says that in Binary mode, recLength functions,
instead of record length (as in Random), to specify the byte at which to
start writing.  So, theoretically, recLength should be able to be set to the
same as Seek()'s pointer position, but this doesn't work.  It seems to add
them together or something.  If anyone knows how to use reclength with
Seek() or by itself, I'd love to know.  I haven't tried using Put() by
itself without
Seek().

Seek() allows you to move past the end of the file.  There's no EOF error.
It just extends the file (if you're writing).

Pretty damn handy.



Sun, 24 Mar 2002 03:00:00 GMT  
 file i/o, random access?


Quote:
> SetFilePointer() is it?  Finally found a trail.
> There must be a common confusion about the VB Seek() function.  There is a
> Seek() listed in the SDK, but it has no articles (in the msdn library).  It
> sounds like it does what SetFilePointer() does.

You might be thinking of the '_llseek' API, often aliased as 'LSeek'.

Steve.

PS. Just read your post number 3. Seek in random-access seeks a
record number, not a byte number; but it isn't necessary because you
can specify the record number in your Get or Put statement. Each
record contains whatever is in your UDT, and is a fixed size, a bit
like slots in a CD rack.

The 'Seek' effect is identical in binary mode if you say 'Seek
RecordNumber*RecordLength'.

Very easy, really :) E-mail me if you like, and I will explain all
(this isn't exactly API stuff).



Tue, 26 Mar 2002 03:00:00 GMT  
 file i/o, random access?
Thanks, Mr. Smith.


Quote:
> The message


Quote:

> > SetFilePointer() is it?  Finally found a trail.

> > There must be a common confusion about the VB Seek() function.  There is
a
> > Seek() listed in the SDK, but it has no articles (in the msdn library).
It
> > sounds like it does what SetFilePointer() does.

> You might be thinking of the '_llseek' API, often aliased as 'LSeek'.

> Steve.

> PS. Just read your post number 3. Seek in random-access seeks a
> record number, not a byte number; but it isn't necessary because you
> can specify the record number in your Get or Put statement. Each
> record contains whatever is in your UDT, and is a fixed size, a bit
> like slots in a CD rack.

> The 'Seek' effect is identical in binary mode if you say 'Seek
> RecordNumber*RecordLength'.

> Very easy, really :) E-mail me if you like, and I will explain all
> (this isn't exactly API stuff).



Tue, 26 Mar 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. reading binary file and writing into a random access file

2. random access file - write to file

3. Random access files - having and finding multiple types of record in one file

4. When I merge 2 random access files the 2nd file doesn't line up correctly

5. Sequential files and random access files

6. Random Access Files-vb.NET

7. number of records in a random access file?

8. Random File Access

9. Random File Access DB

10. Structures and Random Access Files

11. Random access files

12. Random Access files

 

 
Powered by phpBB® Forum Software