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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

751 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