| stream - a file stream opened for reading, or a TCP stream |
|
Reads a 16-bit value from a file or stream and returns it as a value from 0 to 65535. A short occupies 2 bytes, stored least significant byte first. The result is always unsigned 0 to 65535: negative numbers written with WriteShort come back as their low 16 bits (WriteShort -1, ReadShort gives 65535). Shorts are a good middle ground when an int is overkill - tile indices, quantities, 16-bit samples. Reading past the end of the file returns 0 rather than raising an error, so rely on Eof to know where the data stops. See also: WriteShort, ReadByte, ReadInt, Eof. |
; ReadShort Example
; -----------------
; Save some 2-byte shorts so there is something to read
file=WriteFile("demo_shorts.dat")
WriteShort file,10
WriteShort file,365
WriteShort file,65535
CloseFile file
; ReadShort reads a 2-byte value and always returns 0 to 65535
file=ReadFile("demo_shorts.dat")
a=ReadShort(file)
b=ReadShort(file)
c=ReadShort(file)
CloseFile file
Print "Shorts read from demo_shorts.dat:"
Print " "+a
Print " "+b
Print " "+c+" (the largest value a short can hold)"
; Clean up the demo file
DeleteFile "demo_shorts.dat"
Print "Deleted demo_shorts.dat"
Print ""
Print "Press any key to close the example"
WaitKey
End