Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Binary Baloney Baffling Baseball Buff

Posted on 2002-06-13
6
Medium Priority
?
187 Views
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

 
0
Comment
Question by:sodakotahusker
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:rspahitz
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
0
 
LVL 1

Author Comment

by:sodakotahusker
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!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
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.
0
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

by:rspahitz
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.
0
 
LVL 1

Author Comment

by:sodakotahusker
ID: 7076806
rspahitz,

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.  
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 150 total points
ID: 7076812
OK...

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*.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

916 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