ReadInt.htm 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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>ReadInt (filehandle/stream)</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. filehandle/stream = a valid variable set with the OpenFile, ReadFile command, or OpenTCPStream (v1.52+) <br />
  13. The value returned is an integer in the range -2147483648 to 2147483647
  14. </td>
  15. </tr>
  16. </table>
  17. <h1>Description</h1>
  18. <table>
  19. <tr>
  20. <td>
  21. Once you've opened a disk file (or stream) for reading, use this command to read a single integer value from the file. Note, each value written uses 4 bytes of space and is written least significant byte first. Reading beyond the end of file does not result in an error, but each value read will be zero. <br />
  22. <br />
  23. Streams can only be used in Blitz Basic v1.52 or greater.
  24. </td>
  25. </tr>
  26. </table>
  27. <h1><a href=../2d_examples/ReadInt.bb>Example</a></h1>
  28. <table>
  29. <tr>
  30. <td>
  31. ; Reading and writing a file using ReadInt and WriteInt functions <br />
  32. <br />
  33. ; Initialise some variables for the example <br />
  34. Int1% = 10 ; store 10 <br />
  35. Int2% = 365 ; store 365 <br />
  36. Int3% = 2147483647 ; store 2147483647 the largest positive Integer Value in BlitzBasic ) <br />
  37. Int4% = - 2147483648 ; store -2147483648 the largest negative Integer Value in BlitzBasic ) <br />
  38. <br />
  39. ; Open a file to write to <br />
  40. fileout = WriteFile("mydata.dat") <br />
  41. <br />
  42. ; Write the information to the file <br />
  43. WriteInt( fileout, Int1 ) <br />
  44. WriteInt( fileout, Int2 ) <br />
  45. WriteInt( fileout, Int3 ) <br />
  46. WriteInt( fileout, Int4 ) <br />
  47. <br />
  48. ; Close the file <br />
  49. CloseFile( fileout ) <br />
  50. <br />
  51. ; Open the file to Read <br />
  52. filein = ReadFile("mydata.dat") <br />
  53. <br />
  54. Read1 = ReadInt( filein ) <br />
  55. Read2 = ReadInt( filein ) <br />
  56. Read3 = ReadInt( filein ) <br />
  57. Read4 = ReadInt( filein ) <br />
  58. <br />
  59. ; Close the file once reading is finished <br />
  60. CloseFile( filein ) <br />
  61. <br />
  62. Print "Integer Data Read From File - mydata.dat " <br />
  63. Print Read1 <br />
  64. Print Read2 <br />
  65. Print Read3 <br />
  66. Print Read4 <br />
  67. <br />
  68. WaitKey() <br />
  69. </td>
  70. </tr>
  71. </table>
  72. <br>
  73. <a target=_top href=../index.htm>Index</a><br>
  74. <br>
  75. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=ReadInt&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  76. </html>