Files
BlitzNext/_release/help/commands/2d_commands/CloseFile.htm
T
2014-12-08 12:43:20 +13:00

83 lines
2.1 KiB
HTML

<html>
<head>
<title>Blitz3D Docs</title>
<link rel=stylesheet href=../css/commands.css type=text/css>
</head>
<body>
<h1>CloseFile filehandle</h1>
<h1>Parameters</h1>
<table>
<tr>
<td>
filehandle = variable defined with the WriteFile or OpenFile command
</td>
</tr>
</table>
<h1>Description</h1>
<table>
<tr>
<td>
Use this command to close a file previously opened. You should always close a file as soon as you have finished reading or writing to it.
</td>
</tr>
</table>
<h1><a href=../2d_examples/CloseFile.bb>Example</a></h1>
<table>
<tr>
<td>
; Reading and writing custom types to files using ReadFile, WriteFile and CloseFile
<br />
<br />
; Initialise some variables for the example
<br />
Type HighScore
<br />
Field Name$
<br />
Field Score%
<br />
Field Level%
<br />
End Type
<br />
<br />
Best.HighScore = New HighScore
<br />
BestName = "Mark"
<br />
BestScore = 11657
<br />
BestLevel = 34
<br />
<br />
; Open a file to write to
<br />
fileout = WriteFile("mydata.dat")
<br />
<br />
; Write the information to the file
<br />
WriteString( fileout, BestName )
<br />
WriteInt( fileout, BestScore )
<br />
WriteByte( fileout, BestLevel )
<br />
<br />
; Close the file
<br />
CloseFile( fileout )
<br />
<br />
; Open the file to Read
<br />
filein = ReadFile("mydata.dat")
<br />
<br />
; Lets read the Greatest score from the file
<br />
Greatest.HighScore = New HighScore
<br />
GreatestName$ = ReadString$( filein )
<br />
GreatestScore = ReadInt( filein )
<br />
GreatestLevel = ReadByte( filein )
<br />
<br />
; Close the file once reading is finished
<br />
CloseFile( filein )
<br />
<br />
Print "High score record read from - mydata.dat "
<br />
Print
<br />
Write "Name = "
<br />
Print GreatestName
<br />
Write "Score = "
<br />
Print GreatestScore
<br />
Write "Level = "
<br />
Print GreatestLevel
<br />
<br />
WaitKey()
</td>
</tr>
</table>
<br>
<a target=_top href=../index.htm>Index</a><br>
<br>
Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=CloseFile&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
</html>