Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: Negative Integers Do Not Work as Unicode HTML Entity References


View products that this article applies to.

Symptoms

Some functions, such as the Microsoft Visual Basic (VB) and Visual Basic Script (VBScript) AscW function, may return a negative number when you ask for the Unicode value of a non-Latin character (such as Chinese Hanzi, Japanese Kanji or Korean Hangul). When you use this negative number as an HTML entity reference (&#nnnn, where nnnn is either a hexadecimal or decimal Unicode number), you see the entity reference as literal text, instead of the corresponding non-Latin character.

↑ Back to the top


Cause

Unicode numbers occupy a 16-bit positive range from 0 to 65535 (0xFFFF), and cannot be negative.

↑ Back to the top


Resolution

When AscW returns a negative number, it returns the twos complement form of that number. To convert the twos complement notation into normal binary notation, add 0xFFF to the return result. For an example, see the "More Information" section.

↑ Back to the top


More information

Steps to Reproduce Behavior

  1. Save the following HTML code to a file named TestAscW.htm:
    <HTML>
    
    <HEAD>
    <TITLE>PRB: Negative Integers Do Not Work as Unicode HTML Entity  References</TITLE>
    </HEAD>
    
    <SCRIPT language="VBScript">
    
    // The character used below is the Japanese character "go" (8A9E in 
    //Unicode).
    
    sub load()
    	div1.innerHTML = "Actual character is &#35486; & AscW output is &#" & AscW(ChrW(35486))
    end sub
    
    </SCRIPT>
    
    <BODY language="VBScript" onload="load()">
    
    <DIV id="div1">
    
    </DIV>
    
    </BODY>
    
    </HTML>
    					
  2. Open this file in Internet Explorer. The second character reference is displayed as raw text, and not as the Japanese character "go."
To work around this problem, change the script block to the following:
function DecodeAscW(sOutput) 
	sAscVal = AscW(sOutput) 
	If sAscVal < 0 Then 	
		sAscVal = 65536 + sAscVal 
	End If
	DecodeAscW = sAscVal
end function

sub load()
	div1.innerHTML = "Actual character is &#35486; AscW output is &#" &  DecodeAscW(ChrW(35486))
end sub
				

↑ Back to the top


References

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

↑ Back to the top


Article Info
Article ID : 272138
Revision : 4
Created on : 1/1/0001
Published on : 1/1/0001
Exists online : False
Views : 714