Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default How to write binary data to a file

Hi everyone!

I'm probably struck blind at the moment, but I cannot seem to get this
thing right:

I want the equivalent of
Const bufferSize = 10000&
Dim buffer as String

Open "myfile.txt" For Binary Access Read As #1
buffer = Input(bufferSize, 1)
for write operations.

I.e.

Open "myfile.txt" For Binary Access Write As #1
buffer = "something"
Write #1, buffer, len (buffer)

However, Write in that form is not compatible with Binary mode, and if I
open the file "for output", Write packs my buffer string into text
qualifying double quotes. Put, however, totally messes up the data when
I use it like

Open "myfile.txt" For Binary Access Write As #1
buffer = "something"
Put #1, , buffer

and it doesn't seem to be what I want anyways. I could swear I've done
this before - successfully - but right now I don't know how.

Anyone able to help me? I want the output file to contain exactly the
number of bytes that equals the length of buffer, and nothing else.

Thanks in advance!

Lars
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default How to write binary data to a file (solved)

Lars Uffmann wrote:
Open "myfile.txt" For Binary Access Write As #1
buffer = "something"
Put #1, , buffer

and it doesn't seem to be what I want anyways. I could swear I've done
this before - successfully - but right now I don't know how.


Solved my problem: actually I didn't do what I wrote above, but rather I
tried directly outputting a string constant - and Put needs a byref
variable.
The above code works just fine.

Best Regards,

Lars
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default How to write binary data to a file

Is this what you need?


Sub StringToTextFile(strFile As String, strText As String)

Dim hFile As Long

On Error GoTo ERROROUT

hFile = FreeFile
Open strFile For Binary As #hFile
Put #hFile, , strText
Close #hFile

Exit Sub
ERROROUT:

If hFile 0 Then
Close #hFile
End If

End Sub


RBS


"Lars Uffmann" wrote in message
...
Hi everyone!

I'm probably struck blind at the moment, but I cannot seem to get this
thing right:

I want the equivalent of
Const bufferSize = 10000&
Dim buffer as String

Open "myfile.txt" For Binary Access Read As #1
buffer = Input(bufferSize, 1)
for write operations.

I.e.

Open "myfile.txt" For Binary Access Write As #1
buffer = "something"
Write #1, buffer, len (buffer)

However, Write in that form is not compatible with Binary mode, and if I
open the file "for output", Write packs my buffer string into text
qualifying double quotes. Put, however, totally messes up the data when I
use it like

Open "myfile.txt" For Binary Access Write As #1
buffer = "something"
Put #1, , buffer

and it doesn't seem to be what I want anyways. I could swear I've done
this before - successfully - but right now I don't know how.

Anyone able to help me? I want the output file to contain exactly the
number of bytes that equals the length of buffer, and nothing else.

Thanks in advance!

Lars


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default How to write binary data to a file

Yes - I was making a mistake, as stated above. Thank you for your time &
response!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read data from binary file? Valery Excel Programming 4 July 21st 08 04:59 PM
Import binary file and convert to HEX data Fan924 Excel Programming 2 September 25th 07 06:44 PM
Write data in a closed file? Nicolas[_3_] Excel Programming 1 February 1st 07 01:26 AM
Open CSV file, format data and write output to a text file. BristolBloos Excel Programming 1 October 18th 05 03:50 PM
How can I read/write file with binary format??? NC Excel Programming 2 May 27th 04 09:35 AM


All times are GMT +1. The time now is 01:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"