Files
BlitzNext/_release/help/commands/2d_commands/ReadFloat.htm
T
2014-02-26 16:08:39 +13:00

47 lines
3.4 KiB
HTML

<html><head><title>Command: ReadFloat </title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'><link rel='stylesheet' href='../css/commands.css' type='text/css'></head><body><span class='Command'>&nbsp;&nbsp;ReadFloat (filehandle|stream)&nbsp;&nbsp;</span></p><span class='header'>Definition:</span> <br><br><table width='100%' border='0' cellspacing='2' cellpadding='2' align='center'><tr><td>Reads a single floating point value from an open file (or stream).</td></tr></table><span class='header'><br>Parameter Description:</span> <br><br><table width='100%' border='0' cellspacing='2' cellpadding='2' align='center'><tr><td>filehandle|stream = a valid variable set with the OpenFile, ReadFile command, or OpenTCPStream (v1.52+) The value returned is a floating point number.</td></tr></table><p class='header'>Command Description: <br><br><table width='100%' border='0' cellspacing='2' cellpadding='2' align='center'><tr><td>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>
<br>
Streams can only be used in Blitz Basic v1.52 or greater.
<br>
<br>
See also:<br>
<a href='ReadByte.htm'>ReadByte</a>, <a href='ReadShort.htm'>ReadShort</a>, <a href='ReadInt.htm'>ReadInt</a>, <a href='ReadFloat.htm'>ReadFloat</a>, <a href='ReadString$.htm'>ReadString$</a>, <a href='ReadLine$.htm'>ReadLine$</a>, <a href='WriteByte.htm'>WriteByte</a>, <a href='WriteShort.htm'>WriteShort</a>, <a href='WriteInt.htm'>WriteInt</a>, <a href='WriteFloat.htm'>WriteFloat</a>, <a href='WriteShort.htm'>WriteShort</a>, <a href='WriteString.htm'>WriteString</a>, <a href='WriteLine.htm'>WriteLine</a>, <a href='ReadFile.htm'>ReadFile</a>, <a href='WriteFile.htm'>WriteFile</a>, <a href='OpenFile.htm'>OpenFile</a>, <a href='CloseFile.htm'>CloseFile</a>, <a href='Eof.htm'>Eof</a>, <a href='FileType.htm'>FileType</a>, <a href='FilePos.htm'>FilePos</a>, <a href='SeekFile.htm'>SeekFile</a></td></tr></table><p class='header'>Example: <br><br><table width='100%' border='0' cellspacing='2' cellpadding='2' align='center'><tr><td>; Reading and writing a file using ReadFloat and WriteFloat functions<br>
<br>
; Initialise some variables for the example<br>
Num1# = 10.5 ; store 10.5<br>
Num2# = 365.25 ; store 365.25<br>
Num3# = 32767.123 ; 32767.123 is the largest positive Short Integer Value in BlitzBasic )<br>
Num4# = -32768.123 ; -32768.123 the largest negative Short Integer Value in BlitzBasic )<br>
<br>
; Open a file to write to<br>
fileout = WriteFile("mydata.dat")<br>
<br>
; Write the information to the file<br>
WriteFloat( fileout, Num1 )<br>
WriteFloat( fileout, Num2 )<br>
WriteFloat( fileout, Num3 )<br>
WriteFloat( fileout, Num4 )<br>
<br>
; Close the file<br>
CloseFile( fileout )<br>
<br>
; Open the file to Read<br>
filein = ReadFile("mydata.dat")<br>
<br>
Read1# = ReadFloat( filein )<br>
Read2# = ReadFloat( filein )<br>
Read3# = ReadFloat( filein )<br>
Read4# = ReadFloat( filein )<br>
<br>
; Close the file once reading is finished<br>
CloseFile( fileout )<br>
<br>
Print "Floating Point Data Read From File - mydata.dat "<br>
Print Read1<br>
Print Read2<br>
Print Read3<br>
Print Read4<br>
<br>
WaitKey()<br></td></tr></table><p><b><a target="_top" href="../index.htm">Index</a></b></p></body>
</html>