Solved

Binary Baloney Baffling Baseball Buff

Posted on 2002-06-13
6
178 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
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
Comment Utility
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 50 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now