Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binary format within a text file 1

Status
Not open for further replies.

MoonMullen

Programmer
Jun 13, 2001
25
US
I have end-users who download reports from a mainframe that need to be in text format, however the files sometimes come down in binary format. The file is named with the txt extension. My Excel addin, using VBA code, then translates that text file into a workbook. How can I do a quick check on the text file to determine if the data within is truely in a text format? I know it is in a binary format because it looks like this " ×ÇÔz@ÔÉÉ×ÂÒñô@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@ÇÅÕÅÙÁÓ@ÔÖãÖÙâ@ÃÖÙ×ÖÙÁãÉÖÕ". Does anyone have any idea on what I can do? [dazed]
 
The only thing I'm aware of that you could do is try to identify an "always exists" or "never exists" condition in the binary files, then write a test for that. Something like "the binary files never have spaces, so check for at least five spaces in the first 200 characters of the file". Or maybe, "if there are more than 10 '@' symbols in the first 100 characters, it must be binary".

Using a technique or combination of techniques like this, you can probably come up with a 95% solution.

The other approach would be to try to address why some reports come as binary (either by changing that or training your users to avoid those binary reports). But I'm guessing you have already ruled that out as a primary option.
 
You could also search for Chr(0) values. Unless the file is in Unicode format a text file won't contain Chr(0).

-HtH,

Rob

-Focus on the solution to the problem, not the obstacles in the way.-
 
If I were you, I would iterate along the string until I found a binary value of 200 - 220. You will hav eto look at the character values of these, but I think these values are where the non-English characters are(e with accents etc) If you now your text file is in english, these won't be in there. Chr(0) - chr(10) are nulls or carriage returns etc.

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top