78 lines
2.4 KiB
HTML
78 lines
2.4 KiB
HTML
<html>
|
|
<head>
|
|
<title>Blitz3D Docs</title>
|
|
<link rel=stylesheet href=../css/commands.css type=text/css>
|
|
</head>
|
|
<body>
|
|
<h1>WriteShort (filehandle/stream, myinteger)</h1>
|
|
<h1>Parameters</h1>
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
filehandle/stream = a valid variable set with the OpenFile, WriteFile command, or OpenTCPStream (v1.52+)
|
|
<br />
|
|
myinteger = an integer variable (a floating point number can be used but this will be converted to an integer before saving so only the integer part will be saved)
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<h1>Description</h1>
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
Once you've opened a disk file (or stream) for writing, use this command to write a single short integer (16 bit) value to the file. Note, each value written uses 2 bytes and is written least significant byte first. The range of the value saved is 0-65535
|
|
|
|
<br />
|
|
|
|
<br />
|
|
Streams can only be used in Blitz Basic v1.52 or greater.
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<h1><a href=../2d_examples/WriteShort.bb>Example</a></h1>
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
; Reading and writing a file using ReadShort and WriteShort functions
|
|
<br />
|
|
|
|
<br />
|
|
; Initialise some variables for the example
|
|
<br />
|
|
Int1% = 10 ; store 10
|
|
<br />
|
|
Int2% = 365 ; store 365
|
|
<br />
|
|
Int3% = 32767 ; 32767 is the largest positive Short Integer Value in BlitzBasic )
|
|
<br />
|
|
Int4% = -32768 ; -32768 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 />
|
|
WriteShort( fileout, Int1 )
|
|
<br />
|
|
WriteShort( fileout, Int2 )
|
|
<br />
|
|
WriteShort( fileout, Int3 )
|
|
<br />
|
|
WriteShort( fileout, Int4 )
|
|
<br />
|
|
|
|
<br />
|
|
; Close the file
|
|
<br />
|
|
CloseFile( fileout )
|
|
<br />
|
|
|
|
<br />
|
|
; Open the file to Read
|
|
<br />
|
|
filein = ReadFile("mydata.dat")
|
|
<br />
|
|
|
|
<br />
|
|
Read1 = ReadShort( filein )
|
|
<br />
|
|
Read2 = ReadShort( filein )
|
|
<br />
|
|
Read3 = ReadShort( filein )
|
|
<br />
|
|
Read4 = ReadShort( filein )
|
|
<br />
|
|
|
|
<br />
|
|
; Close the file once reading is finished
|
|
<br />
|
|
CloseFile( filein )
|
|
<br />
|
|
|
|
<br />
|
|
Print "Short Integer 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>
|
|
<br>
|
|
<a target=_top href=../index.htm>Index</a><br>
|
|
<br>
|
|
Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=WriteShort&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
|
|
</html>
|