Writing Binary Files With VBA for Excel 95 
Author Message
 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



Sun, 28 Nov 1999 03:00:00 GMT  
 Writing Binary Files With VBA for Excel 95

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

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). 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
-Gil    



Mon, 29 Nov 1999 03:00:00 GMT  
 Writing Binary Files With VBA for Excel 95

I think you'll do better with Put #1 instead of Print #1, which adds a carriage
return and linefeed to the file each time.

  >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
  >
  >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). 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
  >-Gil      
  >



Mon, 29 Nov 1999 03:00:00 GMT  
 Writing Binary Files With VBA for Excel 95

I had a similar.  I solved it by appending a ";" at the end
of the print statement.  It supresses the CR LF characters.

Andre

: 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
:
: 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). 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
: -Gil  
:



Tue, 30 Nov 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VBA and binary file write

2. Determining file Version via VB(word 95, 97, Excel 95 97)

3. Access 95 and (Excel 97 and Excel 95)

4. Problem with slow cell writes in Excel 95

5. VBA for Excel and other Office '95 apps

6. VBA Excel 7.0 (Office 95) Sources.

7. Question on old version of VBA for Excel 95

8. Creating Class in VBA of Excel 95

9. Problems using ODBCDirect in Excel 95 VBA!!!

10. Error-Handling in VBA Excel 95 (V7)

11. Creating Class in VBA of Excel 95

12. Stack Size and VBA (Excel 95)

 

 
Powered by phpBB® Forum Software