ReadFloat.htm 2.3 KB

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