home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Tool Box
/
SIMS_2.iso
/
vb_code1
/
array
/
vbarray.inf
< prev
next >
Wrap
Text File
|
1991-12-02
|
2KB
|
56 lines
Documentation for VBARRAY
VBARRAY demonstrates a method of loading/saving Arrays using the API's file
I/O functions. Any array up to 64k (except user types that contain variable
length strings) can be loaded from a file or saved to a file in a single
operation. For arrays greater than 64k you would need a loop.
No big tricks are involved in doing this, it's simply a matter of getting
around VB's strict type checking. Two API declarations need to be
modified: "lread" and "lwrite" These are currently declared as:
Declare Function lread Lib "Kernel" Alias "_lread" (ByVal hFile As Integer,
ByVal lpBuffer As String, ByVal wBytes As Integer) As Integer
Declare Function lwrite Lib "Kernel" Alias "_lwrite" (ByVal hFile As Integer,
ByVal lpBuffer As String, ByVal wBytes As Integer) As Integer
Change the above functions to read:
Declare Function lread Lib "Kernel" Alias "_lread" (ByVal hFile As Integer,
lpBuffer As Any, ByVal wBytes As Integer) As Integer
Declare Function lwrite Lib "Kernel" Alias "_lwrite" (ByVal hFile As Integer,
lpBuffer As Any, ByVal wBytes As Integer) As Integer
By changing lpBuffer to "As Any" we can pass any Array, or other data type
that we wish to read or write to a file. The only inconvenience is that when
passing strings, we have to explicitly use the "ByVal" keyword.
About the Demo:
VBARRAY demonstrates I/O of three different arrays: Integer, Long Integer,
and User Type. The demo uses a Windows supplied temp file and writes a
demo array of 50 elements. It then reads the array from disk and lists the
"before" and "after" elements. For all three examples VBARRAY writes and
reads the arrays in a single pass providing significantly faster I/O than
the For...Next loop you would need with VB's native I/O functions.
The source code is commented and should answer most of your questions. The
I/O occurs in the Do***Demo functions. I only added comments to the
DoIntDemo function since these also apply to the DoLngIntDemo and DoOtherDemo
functions.
If you have questions or suggestions, I can be reached at CIS 73667,1755
via Email or on the MSBASIC forum. Many thanks to Keith Funk for reviewing
this and for his helpful suggestions.
Enjoy!
Costas Kitsos
December 1991