
Writing Binary Files With VBA for Excel 95
On 11-Jun-97 18:56:18, ME! was so nice to say:
Quote:
> Hi, forgive me if this is a repeat post but i think my news server was
> unable to send my previous message. I am trying to write a binary file
> with
VBA in excel 95. I want to simply write a single character at a
> time to this file. However every time I write to the file I get an
> added 2 characters they are (0D) and (0A). Let me show you an example
> of the code im writing to see if you can suggest a solution.......
> Sub WriteChar
> Dim outchar as string
> Open("MyFile" for output as #1)
> outchar = Chr(&h82)
> Print #1, outchar
> close #1
> End Sub
Hmmm...I don't have access to my VB documentation right now (I'm studying
computer programming but don't have a PC at home) but I'll give it a shot.
(1) For starters, you're opening the file for output, not binary. Use:
Open <filename> for Binary {Access [Read|Write|ReadWrite]} As [#]<filenum>
(2) You're using the Print function, which outputs the content of the
listed variables, followed by a linefeed and carriage return (ASCII 10 and
13). Use the Put function instead. Then use the Get function to read the
data.
Something like this:
--
Dim FileNum as integer, outchar as string
FileTag = Freefile
Open "MyFile" For Binary as #FileNum
Put #FileNum outchar
Close #FileNum
--
Quote:
> I would think that the file would only have 1 character printed in it
> but it appears to have a carrige return or something when i look at it
> with a hex editor. IE: instead of simply (82) i see (82) (0D) (0A).
0D = 13 = Carriage return
0A = 10 = Line feed
Quote:
> Is
> there a different function i can use for writing to the file with the
> added characters? Does any1 know if there is a way around this? Thanks
If I've been any help, maybe have a look at my Dad's art page in return?
http:/www.{*filter*}spc.mb.ca/~llaliber/SteelArt/SteelArt.html
...and if you know anyone interested in art, pass the word around. :)
--
TheWriter <-----> http://www.{*filter*}spc.mb.ca/~llaliber/
Proudly Canadian <-----> Canadien Bien Fier