Binary Baloney Baffling Baseball Buff

Posted on 2002-06-13
Last Modified: 2010-05-02
I am creating a pdf file on a server and returning the binary stream of pdf formatted data via a function return in VB to a middle tier DLL.  When I get the stream on the receiving end I open up a binary file and then dump the info into that file and close it.   It works fine with one exception - it seems to want to write out four bytes at the beginning of the file which break my logic.  These characters are (Hex)  08-00-9C-35
They are not part of the stream.
Can any body tell me what is going on here and how I can prevent it from happening:

the code is:

datastream = object.returnstream(arg1,arg2)

open "c:\junk.pdf" for binary as #1  (i also tried specifying the len as the length of the datastream)

put #1, , datastream   ( I also tried put #1,1,datastream
close #1

Question by:sodakotahusker
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 22

Expert Comment

ID: 7076717
Just guessing, but is the file/datastream 538012 bytes long?

08-00-9C-35 could be read as a low-order double-byte number: &H0008359C = 538012

If so, it's putting the file length at the beginning of the file stream.

You could also try this instead:

open "c:\junk.pdf" for binary as #1  (i also tried specifying the len as the length of the datastream)

print datastream;
close #1

Author Comment

ID: 7076760
Mystery solved.
I was using a variant to hold the stream coming in.  Aparently the length information about the stream was being stored in front of the actual stream.  I changed to a string variable and life is good again!
LVL 16

Expert Comment

ID: 7076762
Could you put datasream in an array of bytes, then write down to file open in binary mode?
You could dimension the array first if you don't want to use a dynamic one.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 22

Expert Comment

ID: 7076787
sodakotahusker, did my comment help you to get there?  (I correctly(?) identified the string as length...)  If so, feel free to accept that comment as your answer.

Author Comment

ID: 7076806

As a matter of a fact it did.  I was wondering how to do this.  How about you copy my solution and make it a comment so I can accept that answer so people who find in the future might not spend hours over this silly issue like I did.  
LVL 22

Accepted Solution

rspahitz earned 50 total points
ID: 7076812

After examining the hex numbers, it occurred to me that these translate into the length of the datastream. (low order, double-byte: 08 00 9C 35 -> &H0008359C = decimal 538012.)

When you investigated this, you found that the length WAS being added because the datastream variable is actually defined as a *variant* rather than as a *string*.

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month5 days, 10 hours left to enroll

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question