ReadBytes.htm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>ReadBytes bank,file/stream,offset,count</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. bank = variable containing handle to valid bank <br />
  13. file/stream = file handle of previously opened file or stream <br />
  14. offset = offset in bytes to write the value <br />
  15. count = how many bytes to write from the offset
  16. </td>
  17. </tr>
  18. </table>
  19. <h1>Description</h1>
  20. <table>
  21. <tr>
  22. <td>
  23. You can read the contents of a disk file (or stream) to a memory bank using this command. <br />
  24. <br />
  25. Note: The file handle must be opened with OpenFile or OpenTCPStream and subsequently closed with CloseFile or CloseTCPStream after the reading operations are complete. <br />
  26. <br />
  27. Return how many bytes successfully read from a stream. <br />
  28. <br />
  29. Streams can only be used in Blitz Basic v1.52 or greater.
  30. <br>
  31. <br>
  32. See also: <a class=small href=WriteBytes.htm>WriteBytes</a>.
  33. </td>
  34. </tr>
  35. </table>
  36. <h1><a href=../2d_examples/ReadBytes.bb>Example</a></h1>
  37. <table>
  38. <tr>
  39. <td>
  40. ; Read/WriteBytes Commands Example <br />
  41. <br />
  42. ; Create a 50 byte memory bank <br />
  43. bnkTest=CreateBank(500) <br />
  44. <br />
  45. ; Let's fill the bank with random data <br />
  46. For t = 1 To 50 <br />
  47. <br />
  48. PokeByte bnkTest,t,Rnd(255) <br />
  49. <br />
  50. Next <br />
  51. <br />
  52. ; Open a file to write to <br />
  53. fileBank=WriteFile("test.bnk") <br />
  54. ; Write the bank to the file <br />
  55. WriteBytes bnkTest,fileBank,0,50 <br />
  56. ; Close it <br />
  57. CloseFile fileBank <br />
  58. <br />
  59. ; Free the bank <br />
  60. FreeBank bnkTest <br />
  61. <br />
  62. ; Make a new one <br />
  63. bnkTest=CreateBank(500) <br />
  64. <br />
  65. ; Open the file to read from <br />
  66. fileBank=OpenFile("test.bnk") <br />
  67. ; Write the bank to the file <br />
  68. ReadBytes bnkTest,fileBank,0,50 <br />
  69. ; Close it <br />
  70. CloseFile fileBank <br />
  71. <br />
  72. ; Write back the results! <br />
  73. For t = 1 To 50 <br />
  74. <br />
  75. Print PeekByte (bnkTest,t) <br />
  76. <br />
  77. Next
  78. </td>
  79. </tr>
  80. </table>
  81. <br>
  82. <a target=_top href=../index.htm>Index</a><br>
  83. <br>
  84. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=ReadBytes&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  85. </html>