Prev: Datagridview Combobox Values
Next: How to display 4 order Polynomial equation from the Excel in VB6
From: Gary on 23 Jul 2010 23:31 I need to add writing a binary file to my application and I haven't had much experience with writing files. I've been trying to understand and use examples found on the web and here is what I've been working with. 'Start code: Dim i As Integer Dim nFileNum As Integer Dim sFilename As String sFilename = "C:\Temp.bin" Open sFilename For Binary Access Write As #nFileNum ' Put data in the file For i = 0 To 15 'Write #nFileNum, , i Put #nFileNum, , i Next i Close #nFileNum 'End code This works but when I look at the file using a hex editor the file is 32 bytes long and has leading zeros (two) in front of each number (or the hex equivalent) byte. I want to be able to write this to a file and have no leading zeros so that the file will be 16 bytes long. I think it has something to do with the # but I'm not sure. I hope what I'm asking can be understood and thanks much for any help.
From: Larry Serflaten on 24 Jul 2010 00:35 "Gary" <private(a)comcast.net> wrote > Dim i As Integer > Put #nFileNum, , i > > This works but when I look at the file using a hex editor the file is 32 > bytes long and has leading zeros (two) in front of each number (or the hex > equivalent) byte. I want to be able to write this to a file and have no > leading zeros Note that you declared i to be an Integer. An Integer is a 2 byte data type. If you want to write just one byte at a time, use a 1 byte data type (Byte). Change the i declaration to As Byte and see if that gets you farther along.... LFS
From: Gary on 25 Jul 2010 11:52 Thank you very much! I've been away from VB too long :( "Larry Serflaten" <serflaten(a)gmail.com> wrote in message news:i2dqi9$nab$1(a)news.eternal-september.org... > > "Gary" <private(a)comcast.net> wrote > >> Dim i As Integer > >> Put #nFileNum, , i > >> >> This works but when I look at the file using a hex editor the file is 32 >> bytes long and has leading zeros (two) in front of each number (or the >> hex >> equivalent) byte. I want to be able to write this to a file and have no >> leading zeros > > Note that you declared i to be an Integer. An Integer is a 2 byte data > type. > If you want to write just one byte at a time, use a 1 byte data type > (Byte). > > Change the i declaration to As Byte and see if that gets you farther > along.... > > LFS > >
|
Pages: 1 Prev: Datagridview Combobox Values Next: How to display 4 order Polynomial equation from the Excel in VB6 |