Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PUT byte data greater than 255 causing error

Status
Not open for further replies.

dommett

Programmer
Apr 30, 2004
33
US
I have a binary file I am writing sequentially. I found when I PUT an integer in it greater than 255 it wrote it in two bytes (as desired) but when I have to return to some previous record # already written and write an integer value greater than 255, I get an Bad File Name or Number error.
 
I would write it as two bytes. You can do this with a bit of arithmetic:
Code:
Public Function GetHiByte(byval MyInt as Integer) As Byte
   GetHiByte = MyInt \ 256
End Function

Public Function GetLoByte(ByVal MyInt As Integer) As Byte
   GetLoByte = MyInt Mod 256
End Function
The first function extracts the top-most byte of an integer by doing an integer-division, which discards any fractional amount. The 2nd function extracts the bottom-most byte of an integer by using the Modulus operator, which only returns the fractional part of a division.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top