|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
output to binaryoh man, i feel pretty stupid for having to ask this, but it's been a while (7 or 8 years)
since i've had to output to binary before. i've been through the help files for "open" and "put", but i must have missed something - even after the 100th time through them. how come when i have On Error Resume Next Kill "C:\test.bin" Open "C:\test.bin" For Binary Access Write Lock Read Write As #1 Put #1, ,"This should be jumbled binary data, not readable stuff." Close #1 the resulting file is in plain ol' english instead of binary when opened up in a text editor? lance p.s. i thought creating a different account with a different name for this post, as it's so embarrassing :-(
Show quote
Hide quote
"Lance" <nu***@business.com> wrote in message Writing in binary mode simply copies the data from memory directly to thenews:%23RbEyiGYFHA.2572@TK2MSFTNGP14.phx.gbl > oh man, i feel pretty stupid for having to ask this, but it's been a > while (7 or 8 years) since i've had to output to binary before. i've > been through the help files for "open" and "put", but i must have > missed something - even after the 100th time through them. how come > when i have > > On Error Resume Next > Kill "C:\test.bin" > Open "C:\test.bin" For Binary Access Write Lock Read Write As #1 > Put #1, ,"This should be jumbled binary data, not readable stuff." > Close #1 > > the resulting file is in plain ol' english instead of binary when > opened up in a text editor? file. With text it actually translates unicode to ansi first but then those bytes are copied to the file and the result is that the plan text appears. With numeric values the result will be "jumbled" but not with strings. If you want the data to be less readable you'll need to encode it somehow. -- Reply to the group so all can participate VB.Net: "Fool me once..." ok, that explains it. i've used binary output for numbers only in the past and hadn't
encountered this before. thanks, lance Show quoteHide quote "Bob Butler" <tiredofit@nospam.com> wrote in message news:Ocf8QsGYFHA.2128@TK2MSFTNGP14.phx.gbl... > "Lance" <nu***@business.com> wrote in message > news:%23RbEyiGYFHA.2572@TK2MSFTNGP14.phx.gbl >> oh man, i feel pretty stupid for having to ask this, but it's been a >> while (7 or 8 years) since i've had to output to binary before. i've >> been through the help files for "open" and "put", but i must have >> missed something - even after the 100th time through them. how come >> when i have >> >> On Error Resume Next >> Kill "C:\test.bin" >> Open "C:\test.bin" For Binary Access Write Lock Read Write As #1 >> Put #1, ,"This should be jumbled binary data, not readable stuff." >> Close #1 >> >> the resulting file is in plain ol' english instead of binary when >> opened up in a text editor? > > Writing in binary mode simply copies the data from memory directly to the > file. With text it actually translates unicode to ansi first but then those > bytes are copied to the file and the result is that the plan text appears. > With numeric values the result will be "jumbled" but not with strings. If > you want the data to be less readable you'll need to encode it somehow. > > -- > Reply to the group so all can participate > VB.Net: "Fool me once..." > > oh man, i feel pretty stupid for having to ask this, but it's been a while <code snipped>> (7 or 8 years) since i've had to output to binary before. i've been > through the help files for "open" and "put", but i must have missed > something - even after the 100th time through them. how come when i have > p.s. i thought creating a different account with a different name for If you want the data to be 'jumbled' then you'll need to encrypt it first > this post, as it's so embarrassing :-( since writing a string to a file in binary mode simply writes the string data (ASCII characters) as they would appear in a text editor for example. One option you have is to compress the data before writing it to a file, not only does this mean that you're reading/writing less data (I/O is always a slow point of applications), it also means that the written data is 'jumbled' in the file as you put it. Have a look at the ZLib article on my page for an example of how to compress data in VB, it's a nice little library and dead easy to use. Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ hi mike,
it wasn't that i was trying to "jumble" that output really, it's just that it wasn't "jumbled" that had me thinking i was doing something wrong. as bob pointed out to me - and as you know - text will appear as text and numbers will appear "jumbled". i had only worked with numbers in binary output in the past and was confused when this output wasn't "jumbled". thanks though, lance Show quoteHide quote "Mike D Sutton" <ED***@mvps.org> wrote in message news:ux2vp4GYFHA.4036@tk2msftngp13.phx.gbl... >> oh man, i feel pretty stupid for having to ask this, but it's been a while (7 or 8 >> years) since i've had to output to binary before. i've been through the help files for >> "open" and "put", but i must have missed something - even after the 100th time through >> them. how come when i have > <code snipped> >> p.s. i thought creating a different account with a different name for this post, as >> it's so embarrassing :-( > > If you want the data to be 'jumbled' then you'll need to encrypt it first since writing > a string to a file in binary mode simply writes the string data (ASCII characters) as > they would appear in a text editor for example. One option you have is to compress the > data before writing it to a file, not only does this mean that you're reading/writing > less data (I/O is always a slow point of applications), it also means that the written > data is 'jumbled' in the file as you put it. > Have a look at the ZLib article on my page for an example of how to compress data in VB, > it's a nice little library and dead easy to use. > Hope this helps, > > Mike > > > - Microsoft Visual Basic MVP - > E-Mail: ED***@mvps.org > WWW: Http://EDais.mvps.org/ > |
|||||||||||||||||||||||