|
-
April 12th, 2009, 02:58 PM
#1
help writing binary(?) data to a file please (Problem Resolved)
Hi everyone. I'm trying to write data to a file and having 2 problems. The data is integer data (0~255) and I've tried using the write & print commands and various conversions with no luck. I'm reading a byte of data at a time from a device, hence the 0~255. If I try writing this to a file I get the ascii characters written to the file, along with a CR & LF. For example, if I try to write '255' to the file and then look at it with a hex editor, I see five bytes written: "32 35 35 0D 0A". What I'd really like to see in the hex editor is "FF" and nothing else.
Can someone help me with the proper conversion or method to write the straight binary data, and also supress the CR & LF?
Thanks in advance!!! Oh, and Happy Easter!!!
Last edited by mtnman82; April 12th, 2009 at 06:34 PM.
-
April 12th, 2009, 05:23 PM
#2
Re: help writing binary(?) data to a file please
You have to open the file in Binary mode so that it will write the raw data that your have.
Code:
Dim hFile As Integer, byteData As Byte
byteData = &HFF
hFile = FreeFile
Open "C:\test.bin" For Binary Access Write As #hFile
Put #hFile, , byteData
Close #hFile
Hope it will help you
-
April 12th, 2009, 06:00 PM
#3
Re: help writing binary(?) data to a file please
Thanks rxbagain!! That seems to fix part of the problem as I am now writing FF to the file in binary form, but there are still extra characters. Running the example above, and openning up the file with a hex editor yields "02 00 FF 00", so we're writing 'STX (start of text)' and NULL characters in addition to the 'FF'.
Any ideas on how to supress the extra characters?
Thanks again!!!
-
April 12th, 2009, 06:33 PM
#4
Re: help writing binary(?) data to a file please
Problem resolved!!!
I neglected to dimension my data as Byte data. When I did this, all worked perfectly. Thanks again!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|