WriteFloat.htm 2.2 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>WriteFloat (filehandle/stream, myFloat)</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. filehandle/stream = a valid variable set with the OpenFile, WriteFile command, or OpenTCPStream (v1.52+) <br />
  13. myFloat = a floating point variable
  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 writing, use this command to write a single floating point number to the file. Note, each value written uses 4 bytes. <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/WriteFloat.bb>Example</a></h1>
  28. <table>
  29. <tr>
  30. <td>
  31. ; Reading and writing a file using ReadFloat and WriteFloat functions <br />
  32. <br />
  33. ; Initialise some variables for the example <br />
  34. Num1# = 10.5 ; store 10.5 <br />
  35. Num2# = 365.25 ; store 365.25 <br />
  36. Num3# = 32767.123 ; 32767.123 is the largest positive Short Integer Value in BlitzBasic ) <br />
  37. Num4# = -32768.123 ; -32768.123 the largest negative Short 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. WriteFloat( fileout, Num1 ) <br />
  44. WriteFloat( fileout, Num2 ) <br />
  45. WriteFloat( fileout, Num3 ) <br />
  46. WriteFloat( fileout, Num4 ) <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# = ReadFloat( filein ) <br />
  55. Read2# = ReadFloat( filein ) <br />
  56. Read3# = ReadFloat( filein ) <br />
  57. Read4# = ReadFloat( filein ) <br />
  58. <br />
  59. ; Close the file once reading is finished <br />
  60. CloseFile( filein ) <br />
  61. <br />
  62. Print "Floating Point 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=WriteFloat&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  76. </html>