WriteBytes.htm 2.2 KB

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