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 - Finding the ascii code of a non-printable.

Reply
 
Old 08-22-2008   #1 (permalink)
HyperAnalyst


 
 

Finding the ascii code of a non-printable.

I was just reading "Today's Word", an email from joelosteen.com, and noticed
"unprintables" (that seemed to be replacing the quote characters); so, I was
trying to figure out what the ascii code was for them.
(I have XP Home, and IE 7)
I put a Visual Basic Script in an html file with the asc() function
....basically,
<script type="text/VBScript">
<!--
Function ascchr(acharC)
Dim t1
t1=asc(acharC)
document.forms(0).outChr.value="asc(" & acharC & ")=" & t1
End Function
(here is a copy of the non-printable [I will put in double-quotes]:"”")
The function seems to be returning "asc(”)=63", decimal 63. Oddly enough,
the question mark on my keyboard, "?", also gives the same value, decimal 63.

How could 2 different "characters" be transformed to the same value, through
"asc()"? Are they really different "characters"? Could this be an
indication of a VB Scripting bug?

My System SpecsSystem Spec
Old 08-22-2008   #2 (permalink)
HyperAnalyst


 
 

RE: Finding the ascii code of a non-printable.

Here's the entire .htm file:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>AscC</title>
<script type="text/javascript">
<!--
function chrfoc() {
document.forms(0).chrChr.value="";
document.forms(0).outChr.value="";
document.forms(0).chrChr.focus();
}
//-->
</script>

<script type="text/VBScript">
<!--
Function ascchr(acharC)
Dim t1
t1=asc(acharC)
document.forms(0).outChr.value="asc(" & acharC & ")=" & t1
ascchr=1
End Function
//-->
</script>
</head>
<body onload="chrfoc()">
<div class="d0">asc(c)
<form method="post" id="frmNnput" action="eval(0)">
<input tabindex="1" accesskey="1" type="text" id="chrChr"
name="chrChr" size="1" value="" /><br />
<input tabindex="2" accesskey="2" type="button" id="chrbtn"
name="chrbtn" value="Chr" class="c0"
onclick="ascchr(document.forms(0).chrChr.value);" /><br /><br />
<input tabindex="3" accesskey="3" type="text" id="outChr"
name="outChr" size="15" value="" class="nw0" /><br />
</form>
</div>
</body>
</html>

-=-=-=-=-=-=-=-=-=-
"HyperAnalyst" wrote:
Quote:

> I was just reading "Today's Word", an email from joelosteen.com, and noticed
> "unprintables" (that seemed to be replacing the quote characters); so, I was
> trying to figure out what the ascii code was for them.
> (I have XP Home, and IE 7)
> I put a Visual Basic Script in an html file with the asc() function
> ...basically,
> <script type="text/VBScript">
> <!--
> Function ascchr(acharC)
> Dim t1
> t1=asc(acharC)
> document.forms(0).outChr.value="asc(" & acharC & ")=" & t1
> End Function
> (here is a copy of the non-printable [I will put in double-quotes]:"”")
> The function seems to be returning "asc(”)=63", decimal 63. Oddly enough,
> the question mark on my keyboard, "?", also gives the same value, decimal 63.
>
> How could 2 different "characters" be transformed to the same value, through
> "asc()"? Are they really different "characters"? Could this be an
> indication of a VB Scripting bug?
My System SpecsSystem Spec
Old 08-22-2008   #3 (permalink)
HyperAnalyst


 
 

RE: Finding the ascii code of a non-printable.

Not sure if it matters, but in addition to XP Home, and IE7, I have:
Office XP with FrontPage, Developer Edition
--
<i>HyperAnalyst</i>


"HyperAnalyst" wrote:
Quote:

> Here's the entire .htm file:
> <?xml version="1.0" encoding="iso-8859-1"?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
> <title>AscC</title>
> <script type="text/javascript">
> <!--
> function chrfoc() {
> document.forms(0).chrChr.value="";
> document.forms(0).outChr.value="";
> document.forms(0).chrChr.focus();
> }
> //-->
> </script>
>
> <script type="text/VBScript">
> <!--
> Function ascchr(acharC)
> Dim t1
> t1=asc(acharC)
> document.forms(0).outChr.value="asc(" & acharC & ")=" & t1
> ascchr=1
> End Function
> //-->
> </script>
> </head>
> <body onload="chrfoc()">
> <div class="d0">asc(c)
> <form method="post" id="frmNnput" action="eval(0)">
> <input tabindex="1" accesskey="1" type="text" id="chrChr"
> name="chrChr" size="1" value="" /><br />
> <input tabindex="2" accesskey="2" type="button" id="chrbtn"
> name="chrbtn" value="Chr" class="c0"
> onclick="ascchr(document.forms(0).chrChr.value);" /><br /><br />
> <input tabindex="3" accesskey="3" type="text" id="outChr"
> name="outChr" size="15" value="" class="nw0" /><br />
> </form>
> </div>
> </body>
> </html>
>
> -=-=-=-=-=-=-=-=-=-
> "HyperAnalyst" wrote:
>
Quote:

> > I was just reading "Today's Word", an email from joelosteen.com, and noticed
> > "unprintables" (that seemed to be replacing the quote characters); so, I was
> > trying to figure out what the ascii code was for them.
> > (I have XP Home, and IE 7)
> > I put a Visual Basic Script in an html file with the asc() function
> > ...basically,
> > <script type="text/VBScript">
> > <!--
> > Function ascchr(acharC)
> > Dim t1
> > t1=asc(acharC)
> > document.forms(0).outChr.value="asc(" & acharC & ")=" & t1
> > End Function
> > (here is a copy of the non-printable [I will put in double-quotes]:"”")
> > The function seems to be returning "asc(”)=63", decimal 63. Oddly enough,
> > the question mark on my keyboard, "?", also gives the same value, decimal 63.
> >
> > How could 2 different "characters" be transformed to the same value, through
> > "asc()"? Are they really different "characters"? Could this be an
> > indication of a VB Scripting bug?
My System SpecsSystem Spec
Old 08-23-2008   #4 (permalink)
mayayana


 
 

Re: Finding the ascii code of a non-printable.

I've seen the same thing in downloaded webpages.
The page looks fine online but when I save a copy
it's loaded with those characters. I've wondered if
it might be the "leftovers" from a UTF-8 2-byte
character marker. Or maybe something put in when
people write HTML in MS Word... But I can't see why
a page in English would have non-ascii characters,
and I've never taken the time to sleuth it out.

Maybe try looking at the source code of your email.
The question marks might just be what you get after
your email program interprets it. If someone else
doesn't come up with an answer then it might help if
you can link to a sample that doesn't require people
to sign up as New Age "Christians" in order to test it out.





My System SpecsSystem Spec
Old 08-23-2008   #5 (permalink)
Old Pedant


 
 

RE: Finding the ascii code of a non-printable.

"HyperAnalyst" wrote:
Quote:

> (here is a copy of the non-printable [I will put in double-quotes]:"”")
> The function seems to be returning "asc(”)=63", decimal 63. Oddly enough,
> the question mark on my keyboard, "?", also gives the same value, decimal 63.
Not odd, at all. The ASC( ) function will never return a value outside of
the range of 0 to 255. If the character is actually outside of that range,
it's treated as a bad translation and you get back a question mark.

Now try using
ASCW( )
where the "W" stands for "W"ide characters. That is, Unicode characters,
which are what VBS *always* uses.

But chances are good that the value you get will be 65535 (which is hex
0xFFFF) meaning that you really have a wrongly translated character, in the
first place. But maybe not.

Personally, I always use
HEX(ASCW(...))
because I find the hex easier to read and look up in various tables.


Quote:

>
> How could 2 different "characters" be transformed to the same value, through
> "asc()"? Are they really different "characters"? Could this be an
> indication of a VB Scripting bug?
My System SpecsSystem Spec
Old 08-24-2008   #6 (permalink)
HyperAnalyst


 
 

RE: Finding the ascii code of a non-printable.

Well, I wasn't getting back any question mark (only numeric values, since
that's asc's "range"); but, Wow, thanks!--that really helped:

I got hex(ascw(”))=94 (or "\u0094"). It's a Cancel Character, "CCH", off
the C1 Controls and Latin-1 Supplement.
Awesome...thanks!!
--
HyperAnalyst


"Old Pedant" wrote:
Quote:

> "HyperAnalyst" wrote:
>
Quote:

> > (here is a copy of the non-printable [I will put in double-quotes]:"”")
> > The function seems to be returning "asc(”)=63", decimal 63. Oddly enough,
> > the question mark on my keyboard, "?", also gives the same value, decimal 63.
>
> Not odd, at all. The ASC( ) function will never return a value outside of
> the range of 0 to 255. If the character is actually outside of that range,
> it's treated as a bad translation and you get back a question mark.
>
> Now try using
> ASCW( )
> where the "W" stands for "W"ide characters. That is, Unicode characters,
> which are what VBS *always* uses.
>
> But chances are good that the value you get will be 65535 (which is hex
> 0xFFFF) meaning that you really have a wrongly translated character, in the
> first place. But maybe not.
>
> Personally, I always use
> HEX(ASCW(...))
> because I find the hex easier to read and look up in various tables.
>
>
>
Quote:

> >
> > How could 2 different "characters" be transformed to the same value, through
> > "asc()"? Are they really different "characters"? Could this be an
> > indication of a VB Scripting bug?
My System SpecsSystem Spec
Old 08-25-2008   #7 (permalink)
Ildhund


 
 

Re: Finding the ascii code of a non-printable.

I get those character combinations in emails all the time. In those
circumstances, they happen when a high-ascii character (129-255) is
converted to UTF-8 and then transmitted using quoted-printable
encoding. Somewhere along the line, the QP is decoded but you're
left with two high-ascii characters instead of the one you're
supposed to get. I don't pretend to understand it. QP is just a hex
representation of the ascii number with '=' as a signal before it,
so easy enough to decode (and why HTML in QP-encoded emails is
peppered with '=3D' - the '=' has itself to be encoded, and 0x3D is
61, ascii for '='). The UTF-8 thing is much more complicated, and
since this problem is most prevalent in mails originating from Mac
systems, it might be something to do with the byte order (which is
different on Mac and PC).

Another thing: AscW() only gives you the first of the two
characters.

Today's Joel newsletter didn't show any funnies at my end, but it
does use the UTF-8 character set and it is transmitted using QP.
--
Noel

"HyperAnalyst" <HyperAnalyst@xxxxxx> wrote in
message news:3D580912-5C8B-4292-86DD-B4761C46BFEB@xxxxxx
Quote:

> Well, I wasn't getting back any question mark (only numeric
> values, since
> that's asc's "range"); but, Wow, thanks!--that really helped:
>
> I got hex(ascw(”))=94 (or "\u0094"). It's a Cancel Character,
> "CCH", off
> the C1 Controls and Latin-1 Supplement.
> Awesome...thanks!!
Quote:

> "Old Pedant" wrote:
Quote:

>> "HyperAnalyst" wrote:
Quote:

>> > (here is a copy of the non-printable [I will put in
>> > double-quotes]:"”")
>> > The function seems to be returning "asc(”)=63", decimal 63.
>> > Oddly enough,
>> > the question mark on my keyboard, "?", also gives the same
>> > value, decimal 63.
>>
>> Not odd, at all. The ASC( ) function will never return a value
>> outside of
>> the range of 0 to 255. If the character is actually outside of
>> that range,
>> it's treated as a bad translation and you get back a question
>> mark.
>>
>> Now try using
>> ASCW( )
>> where the "W" stands for "W"ide characters. That is, Unicode
>> characters,
>> which are what VBS *always* uses.
>>
>> But chances are good that the value you get will be 65535 (which
>> is hex
>> 0xFFFF) meaning that you really have a wrongly translated
>> character, in the
>> first place. But maybe not.
>>
>> Personally, I always use
>> HEX(ASCW(...))
>> because I find the hex easier to read and look up in various
>> tables.
Quote:

>> > How could 2 different "characters" be transformed to the same
>> > value, through
>> > "asc()"? Are they really different "characters"? Could this
>> > be an
>> > indication of a VB Scripting bug?
My System SpecsSystem Spec
Old 08-25-2008   #8 (permalink)
Old Pedant


 
 

RE: Finding the ascii code of a non-printable.


Quote:

> Well, I wasn't getting back any question mark (only numeric values, since
> that's asc's "range"); but, Wow, thanks!--that really helped:
Sorry...I meant the ASC-value *equivalent* of question mark. 0x3F (&H3F in
VBScript code) or 63. If you had done
CHR(ASC(...your funny character...) )
it would have come out as a question mark.
Quote:

> I got hex(ascw(”))=94 (or "\u0094"). It's a Cancel Character, "CCH", off
> the C1 Controls and Latin-1 Supplement.
Well, not necessarily. That depends on the CodePage in use!

Yes, with ISO-8859-1 (which is the old "Latin-1" updated), 0x0094 is indeed
"CCH".

But in Windows-1252 encoding that is the ” character. You might not be able
to see that in this forum; it is the terminating double-quote mark for paired
quotes of the kind MS Word uses when you type in a quote. As in “like this”.

Many people incorrectly say that a page (or message) is encoded with
ISO-8859-1 when in actuality it is encoded in Windows-1252. And I'd bet this
is the case here.

Look here:
http://en.wikipedia.org/wiki/ISO/IEC_8859-1
Look especially at the paragraph titled "The ISO-8859-1/Windows-1252 mixup"
and then look here:
http://en.wikipedia.org/wiki/Windows-1252

So... I'm betting you are *actually* seeing text in WIndows-1252 encoding
and you are seeing a "right-curly-quote" character.
My System SpecsSystem Spec
Old 08-25-2008   #9 (permalink)
Old Pedant


 
 

Re: Finding the ascii code of a non-printable.



"Ildhund" wrote:
Quote:

> Another thing: AscW() only gives you the first of the two
> characters.
What are you talking about? If the character has been encoded as =3D or
whatever, then ASCW is useless. It's only when you see characters such as
‘curly apostrophes’ and “curly quotes” and the like that ASCW is useful.


My System SpecsSystem Spec
Old 08-26-2008   #10 (permalink)
HyperAnalyst


 
 

RE: Finding the ascii code of a non-printable.

And I though the Hex(Ascw(c)) was going to give me the info to help these
guys out....boy was I wrong! --it seems to just get deeper and deeper:
I was reading this email with the unprintables in a webmail reader (Cinti.
Bell WebMail [for fuse.net])...

I, with XP Home, and Office XP Pro, w/ FrontPage (Developer edition), and
with IE7, looked on the toolbar (lower right), near the blue help circle
icon--my "Edit" button was grey'd-out, so I did an alt/view/source.

Bummer #1--notepad opened, even though I had my default editor set to
FrontPage (I'm not sure FP would have helped, even, at this point).
Although I was able to see the html code, and see that no encoding
was coded (webmail's fault, probably [no Content-Type header (of HTTP), and
no encoding pseudo-attribute {XML declaration}]), the bummer was: I'm not
sure if, when I see the little square, way down in the source, and copy it
from Notepad, and paste it into my nifty VBScript Web-program to translate
the character, that the same byte(-sequence) will really end up in "asc()",
as a parameter {one thing I did was, since I hit view/source, and had the
code, was to add both a Content-Type header, and encoding pseudo-attribute,
but I didn't see any change in the appearance of the unprintable, as I though
I would}.
XP's Notepad has Unicode, Ansi, UTF-8 (and Unicode Big Endian); but, I
hadn't save anything yet, so I wasn't sure if the unprintable had been
translated, or what.

BUMMER #2: The "Encoding" switch, or what ever it's called, near the blue
help circle icon (toolbar encoding switch, I guess), that allows switching of
the encoding from "Western European Windows" to "Western European ISO"...it
reloaded the webmail page; and, the appearance of the unprintable, Well, the
"boxes" changed to quote characters, except each was preceeded by a capital
Latin A with a circumflex (however it didn't change the new html page I
created by adding the encoding to the "source" notepad showed me)....now I'm
not sure if what was really in there was a UTF-8 multibyte character. No
matter what I select, I still see a "box" character.

HOWEVER: the character following the A_circumflex (looked like a "smart
quote" [ironically named, huh?]) did appear to have a different "ascii code"
according to my nifty VBScript Web-program {hex(ascw(”))=201D}.

Anyone know if there's a sure-fire way to tell what the damn thing really is?

--
HyperAnalyst
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: ASCII or TBCP Vista print fax & scan
Ascii VB Script
How to search non-printable character in Reg Exp? PowerShell
Format a string with non printable chars PowerShell
RE: Format a string with non printable chars 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