home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / array / vbarray.inf < prev    next >
Text File  |  1991-12-02  |  2KB  |  56 lines

  1.                         Documentation for VBARRAY
  2.  
  3. VBARRAY demonstrates a method of loading/saving Arrays using the API's file
  4. I/O functions.  Any array up to 64k (except user types that contain variable 
  5. length strings) can be loaded from a file or saved to a file in a single 
  6. operation.  For arrays greater than 64k you would need a loop.
  7.  
  8. No big tricks are involved in doing this, it's simply a matter of getting
  9. around VB's strict type checking.  Two API declarations need to be 
  10. modified: "lread" and "lwrite"  These are currently declared as:
  11.  
  12.  
  13. Declare Function lread Lib "Kernel" Alias "_lread" (ByVal hFile As Integer, 
  14.                ByVal lpBuffer As String, ByVal wBytes As Integer) As Integer
  15.  
  16. Declare Function lwrite Lib "Kernel" Alias "_lwrite" (ByVal hFile As Integer, 
  17.                ByVal lpBuffer As String, ByVal wBytes As Integer) As Integer
  18.  
  19.  
  20. Change the above functions to read:
  21.  
  22. Declare Function lread Lib "Kernel" Alias "_lread" (ByVal hFile As Integer, 
  23.                lpBuffer As Any, ByVal wBytes As Integer) As Integer
  24.  
  25. Declare Function lwrite Lib "Kernel" Alias "_lwrite" (ByVal hFile As Integer, 
  26.                lpBuffer As Any, ByVal wBytes As Integer) As Integer
  27.  
  28.  
  29. By changing lpBuffer to "As Any" we can pass any Array, or other data type
  30. that we wish to read or write to a file.  The only inconvenience is that when
  31. passing strings, we have to explicitly use the "ByVal" keyword.
  32.  
  33.  
  34. About the Demo:
  35.  
  36. VBARRAY demonstrates I/O of three different arrays: Integer, Long Integer, 
  37. and User Type.  The demo uses a Windows supplied temp file and writes a
  38. demo array of 50 elements.  It then reads the array from disk and lists the
  39. "before" and "after" elements.  For all three examples VBARRAY writes and 
  40. reads the arrays in a single pass providing significantly faster I/O than
  41. the For...Next loop you would need with VB's native I/O functions.  
  42.  
  43. The source code is commented and should answer most of your questions.  The
  44. I/O occurs in the Do***Demo functions.  I only added comments to the
  45. DoIntDemo function since these also apply to the DoLngIntDemo and DoOtherDemo
  46. functions.
  47.  
  48. If you have questions or suggestions, I can be reached at CIS 73667,1755
  49. via Email or on the MSBASIC forum.  Many thanks to Keith Funk for reviewing
  50. this and for his helpful suggestions.
  51.  
  52. Enjoy!
  53.  
  54. Costas Kitsos
  55. December 1991
  56.