Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Convert Byte() to string

Reply
 
Old 08-05-2008   #1 (permalink)
XP


 
 

Convert Byte() to string

I have a function to read a binary file. I now need to convert the binary to
a string. Does someone by chance have a function that does this? If so could
you please post it, or show me an alternate method, or show me how I can
tweak my code so far (see below) to return a string from the original binary?

Function GetBinaryFileStream(argFullName)
Const adTypeBinary = 1
Dim oBinaryStream
Set oBinaryStream = CreateObject("ADODB.Stream")
oBinaryStream.Type = adTypeBinary
oBinaryStream.Open
oBinaryStream.LoadFromFile argFullName
GetBinaryFileStream = oBinaryStream.Read
End Function

Thanks much in advance.

My System SpecsSystem Spec
Old 08-05-2008   #2 (permalink)
mayayana


 
 

Re: Convert Byte() to string

I have a class I wrote that uses Textstream
and provides full binary file functionality -
reading, writing, returning numeric values
represented by a series of bytes... the basic
things that one would want to do with a binary file.

www.jsware.net/jsware/scripts.php5#bints

Textstream can do it all. You just have to be
careful of how you handle data that might contain
nulls.
A string, a stream and an array are not really
different things, so I don't know what you mean
by converting a binary file to string. Textstream
will read it out as a string, and that string can be
handled, or written to a new file, but you can't
"look at it too closely" unless you convert the nulls.

Quote:

> I have a function to read a binary file. I now need to convert the binary
to
Quote:

> a string. Does someone by chance have a function that does this? If so
could
Quote:

> you please post it, or show me an alternate method, or show me how I can
> tweak my code so far (see below) to return a string from the original
binary?
Quote:

>
> Function GetBinaryFileStream(argFullName)
> Const adTypeBinary = 1
> Dim oBinaryStream
> Set oBinaryStream = CreateObject("ADODB.Stream")
> oBinaryStream.Type = adTypeBinary
> oBinaryStream.Open
> oBinaryStream.LoadFromFile argFullName
> GetBinaryFileStream = oBinaryStream.Read
> End Function
>
> Thanks much in advance.

My System SpecsSystem Spec
Old 08-05-2008   #3 (permalink)
Paul Randall


 
 

Re: Convert Byte() to string


"XP" <XP@xxxxxx> wrote in message
news:9747CDDE-1451-40BD-AE0A-D5E70F3A52B3@xxxxxx
Quote:

>I have a function to read a binary file. I now need to convert the binary
>to
> a string. Does someone by chance have a function that does this? If so
> could
> you please post it, or show me an alternate method, or show me how I can
> tweak my code so far (see below) to return a string from the original
> binary?
>
> Function GetBinaryFileStream(argFullName)
> Const adTypeBinary = 1
> Dim oBinaryStream
> Set oBinaryStream = CreateObject("ADODB.Stream")
> oBinaryStream.Type = adTypeBinary
> oBinaryStream.Open
> oBinaryStream.LoadFromFile argFullName
> GetBinaryFileStream = oBinaryStream.Read
> End Function
You are half way there. The ADODB.Stream is quite versatile, but you have
to 'read the manual' to make full use of this versatility.
http://msdn.microsoft.com/en-us/library/ms677486.aspx is a good place to
start.

It has been a while since I played with this, but I think that between the
last two stream-related statements in your function, you need to set the
stream pointer to the first character in the stream and change the stream
type from binary to text. There may also be requirements to have a certain
combination of stream charset and the script's Locale (read about the
Locale-related functions in the VBScript help file.

Code like this takes care of the stream stuff:
stream.position = 0
stream.type = 2
stream.charset = "x-ansi"

I think the VBScript locale has to be set to 1033.

For more info, do a groups.google search:
http://groups.google.com/groups/sear....*&qt_s=Search

-Paul Randall


My System SpecsSystem Spec
Old 08-06-2008   #4 (permalink)
XP


 
 

Re: Convert Byte() to string

Hi Mayayana,

Thanks! Our internet Nazi's are blocking downloads of zip files so I can't
get your Clsbin package at work; however, I will download it tonight at home
and check it out, thanks for responding.


"mayayana" wrote:
Quote:

> I have a class I wrote that uses Textstream
> and provides full binary file functionality -
> reading, writing, returning numeric values
> represented by a series of bytes... the basic
> things that one would want to do with a binary file.
>
> www.jsware.net/jsware/scripts.php5#bints
>
> Textstream can do it all. You just have to be
> careful of how you handle data that might contain
> nulls.
> A string, a stream and an array are not really
> different things, so I don't know what you mean
> by converting a binary file to string. Textstream
> will read it out as a string, and that string can be
> handled, or written to a new file, but you can't
> "look at it too closely" unless you convert the nulls.
>
>
Quote:

> > I have a function to read a binary file. I now need to convert the binary
> to
Quote:

> > a string. Does someone by chance have a function that does this? If so
> could
Quote:

> > you please post it, or show me an alternate method, or show me how I can
> > tweak my code so far (see below) to return a string from the original
> binary?
Quote:

> >
> > Function GetBinaryFileStream(argFullName)
> > Const adTypeBinary = 1
> > Dim oBinaryStream
> > Set oBinaryStream = CreateObject("ADODB.Stream")
> > oBinaryStream.Type = adTypeBinary
> > oBinaryStream.Open
> > oBinaryStream.LoadFromFile argFullName
> > GetBinaryFileStream = oBinaryStream.Read
> > End Function
> >
> > Thanks much in advance.
>
>
>
My System SpecsSystem Spec
Old 08-06-2008   #5 (permalink)
XP


 
 

Re: Convert Byte() to string

Hi Paul,

Thanks for the link and your response; I will endeavor to read the manual;
it's just that immediate gratification is so much more satisfying (not to
mention deadlines of course)...don't you think? ; )


"Paul Randall" wrote:
Quote:

>
> "XP" <XP@xxxxxx> wrote in message
> news:9747CDDE-1451-40BD-AE0A-D5E70F3A52B3@xxxxxx
Quote:

> >I have a function to read a binary file. I now need to convert the binary
> >to
> > a string. Does someone by chance have a function that does this? If so
> > could
> > you please post it, or show me an alternate method, or show me how I can
> > tweak my code so far (see below) to return a string from the original
> > binary?
> >
> > Function GetBinaryFileStream(argFullName)
> > Const adTypeBinary = 1
> > Dim oBinaryStream
> > Set oBinaryStream = CreateObject("ADODB.Stream")
> > oBinaryStream.Type = adTypeBinary
> > oBinaryStream.Open
> > oBinaryStream.LoadFromFile argFullName
> > GetBinaryFileStream = oBinaryStream.Read
> > End Function
>
> You are half way there. The ADODB.Stream is quite versatile, but you have
> to 'read the manual' to make full use of this versatility.
> http://msdn.microsoft.com/en-us/library/ms677486.aspx is a good place to
> start.
>
> It has been a while since I played with this, but I think that between the
> last two stream-related statements in your function, you need to set the
> stream pointer to the first character in the stream and change the stream
> type from binary to text. There may also be requirements to have a certain
> combination of stream charset and the script's Locale (read about the
> Locale-related functions in the VBScript help file.
>
> Code like this takes care of the stream stuff:
> stream.position = 0
> stream.type = 2
> stream.charset = "x-ansi"
>
> I think the VBScript locale has to be set to 1033.
>
> For more info, do a groups.google search:
> http://groups.google.com/groups/sear....*&qt_s=Search
>
> -Paul Randall
>
>
>
My System SpecsSystem Spec
Old 08-06-2008   #6 (permalink)
mayayana


 
 

Re: Convert Byte() to string

>
Quote:

> Thanks! Our internet Nazi's are blocking downloads of zip files
It could be my site, too, unless you know for
sure that you have such a restriction. I try to
block "download helpers" because they're nearly
all sloppy -- and unnecessary -- programs that
download multiple copies of everything. (I started the
blocking one day after someone using what I think
was GetRight downloaded 36MB worth of a 300KB file.
Now GetRight just calls the server, repeatedly to get
another 403 response. It will call every 6 seconds,
sometimes for hours!)

So if you were using
Download Accelerator, GetRight, Free Download
Manager, etc., you'd probably get a 403 (access
forbidden) when trying to download the zip. In fact,
people using FDM are unfortunately blocked from almost
the entire site, including webpages, due to the way that
FDM hijacks the IE userAgent string for advertising
purposes.


My System SpecsSystem Spec
Old 08-06-2008   #7 (permalink)
Paul Randall


 
 

Re: Convert Byte() to string


"mayayana" <mayaXXyana@xxxxxx> wrote in message
news:eOhfMa89IHA.4536@xxxxxx
Quote:
Quote:

> >
>> Thanks! Our internet Nazi's are blocking downloads of zip files
>
> It could be my site, too, unless you know for
> sure that you have such a restriction. I try to
> block "download helpers" because they're nearly
> all sloppy -- and unnecessary -- programs that
> download multiple copies of everything. (I started the
> blocking one day after someone using what I think
> was GetRight downloaded 36MB worth of a 300KB file.
> Now GetRight just calls the server, repeatedly to get
> another 403 response. It will call every 6 seconds,
> sometimes for hours!)
>
> So if you were using
> Download Accelerator, GetRight, Free Download
> Manager, etc., you'd probably get a 403 (access
> forbidden) when trying to download the zip. In fact,
> people using FDM are unfortunately blocked from almost
> the entire site, including webpages, due to the way that
> FDM hijacks the IE userAgent string for advertising
> purposes.
Thanks for this info on the "helpers".
Do you know of any way for the end user to learn about how badly the helper
is hurting to web site being accessed?

-Paul Randall


My System SpecsSystem Spec
Old 08-06-2008   #8 (permalink)
Paul Randall


 
 

Re: Convert Byte() to string

Yes, I like the immediate gratification too -- at least some code that I can
run and see that it actually does what I want. In this case, I don't have
that to give you. The google search link I gave you gets you to a specific
thread that talks about this and has some code. If you search for some of
the key words used in this section of my response:
Quote:
Quote:

>> stream.position = 0
>> stream.type = 2
>> stream.charset = "x-ansi"
then you may find a bunch of links, some of which may have some code you can
copy and paste to get your job done. Its been a while, so I don't remember
the details of what was posted.

-Paul Randall

"XP" <XP@xxxxxx> wrote in message
news:E02BF9ED-52D2-43B6-BABB-71E9EDC6CD20@xxxxxx
Quote:

> Hi Paul,
>
> Thanks for the link and your response; I will endeavor to read the manual;
> it's just that immediate gratification is so much more satisfying (not to
> mention deadlines of course)...don't you think? ; )
>
>
> "Paul Randall" wrote:
>
Quote:

>>
>> "XP" <XP@xxxxxx> wrote in message
>> news:9747CDDE-1451-40BD-AE0A-D5E70F3A52B3@xxxxxx
Quote:

>> >I have a function to read a binary file. I now need to convert the
>> >binary
>> >to
>> > a string. Does someone by chance have a function that does this? If so
>> > could
>> > you please post it, or show me an alternate method, or show me how I
>> > can
>> > tweak my code so far (see below) to return a string from the original
>> > binary?
>> >
>> > Function GetBinaryFileStream(argFullName)
>> > Const adTypeBinary = 1
>> > Dim oBinaryStream
>> > Set oBinaryStream = CreateObject("ADODB.Stream")
>> > oBinaryStream.Type = adTypeBinary
>> > oBinaryStream.Open
>> > oBinaryStream.LoadFromFile argFullName
>> > GetBinaryFileStream = oBinaryStream.Read
>> > End Function
>>
>> You are half way there. The ADODB.Stream is quite versatile, but you
>> have
>> to 'read the manual' to make full use of this versatility.
>> http://msdn.microsoft.com/en-us/library/ms677486.aspx is a good place to
>> start.
>>
>> It has been a while since I played with this, but I think that between
>> the
>> last two stream-related statements in your function, you need to set the
>> stream pointer to the first character in the stream and change the stream
>> type from binary to text. There may also be requirements to have a
>> certain
>> combination of stream charset and the script's Locale (read about the
>> Locale-related functions in the VBScript help file.
>>
>> Code like this takes care of the stream stuff:
>> stream.position = 0
>> stream.type = 2
>> stream.charset = "x-ansi"
>>
>> I think the VBScript locale has to be set to 1033.
>>
>> For more info, do a groups.google search:
>> http://groups.google.com/groups/sear....*&qt_s=Search
>>
>> -Paul Randall
>>
>>
>>

My System SpecsSystem Spec
Old 08-06-2008   #9 (permalink)
mayayana


 
 

Re: Convert Byte() to string

Quote:

> Thanks for this info on the "helpers".
> Do you know of any way for the end user to learn about how badly the
helper
Quote:

> is hurting to web site being accessed?
>
I've never used a "helper" before myself, so
my only experience is with my own site. I like
to read the server "raw" logs daily, to see
where people linked from, find out when I
have bad links, etc. That's how I started seeing
the problem of download helpers. I don't know how
much the end user can know. I send a 403 to
helpers on my site, but none of the helper programs
seems to be designed to recognize a 403 response.
So there's no way for me to tell people why they're
being blocked.

As I understand it, helper programs originated
with dial-up, as a way to make sure that a download
didn't get dropped partway through. They typically
work by opening numerous connections to the server,
each requesting only part of the download file. That's
a somewhat questionable logic with highspeed, except
when one is downloading something like a 700MB CD
ISO. And it also, often, doesn't work anyway because
many servers won't allow multiple connections from the
same IP. But beyond the issue of their real usefulness, from
reading my logs I find that helpers usually download several
times the bytage of a file. On my own site I have few
downloads over 100 KB, yet I often see people on highspeed
connections downloading a 50KB file in 5 or 6 pieces.
By the time it's done they've downloaded maybe 150 KB
total. Or sometimes they just download the whole file numerous
times within a few seconds. Often they send the server a
browser userAgent on the first download and then download
several more times with a custom helper userAgent string.
Ironically, people don't notice because with highspeed
it only takes a few seconds either way. I often wonder
what people experience when they've downloaded successfully,
say, twice, and were blocked four times, all within 8 seconds.
Did they get the file or do they see it as blocked?

The problem for webmasters is 1) excess traffic that's
unnecessary and 2) difficulty counting actual downloads.

I can't identify all helpers with certainty because they
vary in how they identify themselves to the server. The popular
ones like FDM and Download Accelerator seem to be minor
nuisances, downloading 2-6 copies instead of 1. I have reason
to believe that GetRight is by far the worst, calling the server
over and over again, often hundreds of times. (GetRight shows
a dummy userAgent, so I had to identify it based on several
bits of circumstantial evidence.) I don't know whether it's just
badly designed or whether maybe it's outdated.
The behavior makes no sense. But in general all of the helpers
I've seen seem to be poorly designed in that they download
multiples, clearly not keeping track of what they're doing.
(And in most cases these are multiple downloads with a 200
code, not a 206. In other words, they're not downloading
pieces. They're downloading the whole thing redundantly.)

Another annoyance is the programs that download one of
everything linked from a page. I suspect the people who do
that are probably also the ones who never get around to
looking at what they've downloaded. They're too busy hoarding
more files. But those programs (scrapers?) at least seem to
work properly. I seldom see a "scraper" download more than it
needs to.


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Read Byte Array into String for Delimiting? .NET General
Convert to & from base64 String PowerShell
convert int to numeric (formatted) string .NET General
Convert Byte to Binary PowerShell
HowTo: Convert int/Byte/Byte[] to Hex PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46