How to Output binary data to a file ? 
Author Message
 How to Output binary data to a file ?

Quote:

> I would like to output some data to a file. The data is text data with fixed
> length records.
> The problem is that I dont want the CR/LF on the end of each record. I have
> tried Put and Write but they seem to put a CR/LF on the end of each record.

> Here is a sample what I am doing.

> intFile=FreeFile
> Open "test.dat" For Output as intFile

> strRec="04101999MORAN   MICHAEL     "
> Write #intFile,strRec

> Close #intFile

> The output data has fixed length text fields, so in the above example :
> Bytes     Field
> 1-8         Date
> 8-16       Surname
> 17-28     Given names

If you want to add several records without the CR/LF, why not keep
adding them to your string before you Write it to the file?
  strRec="04101999MORAN   MICHAEL     "
  strRec = strRec & "05847362WILSON  WOODY       "
  strRec = strRec & "09043461HOWELL  THURSTON    "
etc... Then Write or Print it
p.s. - only 9 characters for Surname?  Lotsa my neighbors would get the
-ski chopped off their names!
--
Jim in Cleveland
If you're writing to me, in my address
change "REAL_Address.see.below" to "worldnet.att.net"

"What's so funny 'bout peace, love & understanding?"
     - Nick Lowe



Thu, 21 Mar 2002 03:00:00 GMT  
 How to Output binary data to a file ?
I would like to output some data to a file. The data is text data with fixed
length records.
The problem is that I dont want the CR/LF on the end of each record. I have
tried Put and Write but they seem to put a CR/LF on the end of each record.

Here is a sample what I am doing.

intFile=FreeFile
Open "test.dat" For Output as intFile

strRec="04101999MORAN   MICHAEL     "
Write #intFile,strRec

Close #intFile

The output data has fixed length text fields, so in the above example :
Bytes     Field
1-8         Date
8-16       Surname
17-28     Given names

Please help,
Michael.



Fri, 22 Mar 2002 03:00:00 GMT  
 How to Output binary data to a file ?
Michael

Use the Print # statement and semicolons (;) to supress the CrLfs .

For example:

Dim s1 As String, s2 As String, s3 As String
s1 = "abcd"
s2 = "efgh"
s3 = "ijkl"

Open "c:\xyz.txt" For Output As #1
Print #1, s1;
Print #1, s2;
Print #1, s3;
Close #1

or

Open "c:\xyz.txt" For Output As #1
Print #1, s1; s2; s3;
Close #1

Both of the above result in a file containing one line:  abcdefghijkl

John.........

Quote:

> I would like to output some data to a file. The data is text data with fixed
> length records.
> The problem is that I dont want the CR/LF on the end of each record. I have
> tried Put and Write but they seem to put a CR/LF on the end of each record.

> Here is a sample what I am doing.

> intFile=FreeFile
> Open "test.dat" For Output as intFile

> strRec="04101999MORAN   MICHAEL     "
> Write #intFile,strRec

> Close #intFile

> The output data has fixed length text fields, so in the above example :
> Bytes     Field
> 1-8         Date
> 8-16       Surname
> 17-28     Given names

> Please help,
> Michael.



Fri, 22 Mar 2002 03:00:00 GMT  
 How to Output binary data to a file ?
Thanks John.
I had thought of trying the semicolon, but it wasnt documented in the help
(unless I missed it), so I didnt bother trying it.


Quote:
> Michael

> Use the Print # statement and semicolons (;) to supress the CrLfs .

> For example:

> Dim s1 As String, s2 As String, s3 As String
> s1 = "abcd"
> s2 = "efgh"
> s3 = "ijkl"

> Open "c:\xyz.txt" For Output As #1
> Print #1, s1;
> Print #1, s2;
> Print #1, s3;
> Close #1

> or

> Open "c:\xyz.txt" For Output As #1
> Print #1, s1; s2; s3;
> Close #1

> Both of the above result in a file containing one line:  abcdefghijkl

> John.........


> > I would like to output some data to a file. The data is text data with
fixed
> > length records.
> > The problem is that I dont want the CR/LF on the end of each record. I
have
> > tried Put and Write but they seem to put a CR/LF on the end of each
record.

> > Here is a sample what I am doing.

> > intFile=FreeFile
> > Open "test.dat" For Output as intFile

> > strRec="04101999MORAN   MICHAEL     "
> > Write #intFile,strRec

> > Close #intFile

> > The output data has fixed length text fields, so in the above example :
> > Bytes     Field
> > 1-8         Date
> > 8-16       Surname
> > 17-28     Given names

> > Please help,
> > Michael.



Sat, 23 Mar 2002 03:00:00 GMT  
 How to Output binary data to a file ?
Yeh, 9 characters is not much for a surname but it's just an example.
The problem with using a string is that there could be thousands of records
that need to be written to the file, so the string would be huge.

thanks for the reply



Quote:

> > I would like to output some data to a file. The data is text data with
fixed
> > length records.
> > The problem is that I dont want the CR/LF on the end of each record. I
have
> > tried Put and Write but they seem to put a CR/LF on the end of each
record.

> > Here is a sample what I am doing.

> > intFile=FreeFile
> > Open "test.dat" For Output as intFile

> > strRec="04101999MORAN   MICHAEL     "
> > Write #intFile,strRec

> > Close #intFile

> > The output data has fixed length text fields, so in the above example :
> > Bytes     Field
> > 1-8         Date
> > 8-16       Surname
> > 17-28     Given names

> If you want to add several records without the CR/LF, why not keep
> adding them to your string before you Write it to the file?
>   strRec="04101999MORAN   MICHAEL     "
>   strRec = strRec & "05847362WILSON  WOODY       "
>   strRec = strRec & "09043461HOWELL  THURSTON    "
> etc... Then Write or Print it
> p.s. - only 9 characters for Surname?  Lotsa my neighbors would get the
> -ski chopped off their names!
> --
> Jim in Cleveland
> If you're writing to me, in my address
> change "REAL_Address.see.below" to "worldnet.att.net"

> "What's so funny 'bout peace, love & understanding?"
>      - Nick Lowe



Sat, 23 Mar 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Binary chars in output using Open xxxx For Output As #1

2. Writing binary files to output

3. Write ADO Field containing binary data (files) to the file system

4. Binary Data in SQL 2000/Conver to Bitmap Data For Data Grid View

5. Creating a 2 dimension array and output the data as *.CSV file

6. Write image data as binary to append existing file

7. Write data in binary file / Convert Image

8. Moving Binary Data between files fast!

9. Moving Binary data between files quickly.

10. Reading/Writing Data for Binary Files

11. How to retrieve data from binary files?

12. Populating an array with data from a binary file

 

 
Powered by phpBB® Forum Software