I am using windows 2003 server english version. I got the folloing message
when I put a big5 code to CHR function to get a ANSI character

Microsoft VBScript runtime (0x800A0005)
Invalid procedure call or argument: 'Chr'

I found that i cannot pass a number greater than 255 to the function. The
code works before in windows 2000 server traditional chinese version. Is
there any function/code I could use to translate a 2-bytes big5 code to utf-8
code?

Re: ASP: using Chr to display big 5 character by Tom

Tom
Wed Dec 13 07:45:27 CST 2006

The ChrW() function is intended for such Unicode applications.

Tom Lavedas
============
http://members.cox.net/tglbatch/wsh/

Arran wrote:
> I am using windows 2003 server english version. I got the folloing message
> when I put a big5 code to CHR function to get a ANSI character
>
> Microsoft VBScript runtime (0x800A0005)
> Invalid procedure call or argument: 'Chr'
>
> I found that i cannot pass a number greater than 255 to the function. The
> code works before in windows 2000 server traditional chinese version. Is
> there any function/code I could use to translate a 2-bytes big5 code to utf-8
> code?


Re: using Chr to display big 5 character by Paul

Paul
Fri Dec 15 13:38:52 CST 2006

Having grown up in an ANSI world, I was shocked to find that in certain
locales, the 'w' and non-w versions of functions Chr and Asc handle 16-bit
values. Locale 1082 (Maltese) is one such locale. The VBScript functons
GetLocale and SetLocale can help you play with locale-related things.

I don't have any experience with the big5 charset and little experience with
UTF8, so I doubt that I would recognize a correct translation. Here is a
routine you might want to play with, that doesn't require changing locales:

Option Explicit
Dim strTemp, iStart, iEnd
strTemp = XMLEncode("utf-8", ChrW(8216))
If Len(strTemp) > 47 Then
iStart = Instr(strTemp, "<test>") + 6
iEnd = Instr(iStart, strTemp, "</test>")
MsgBox "utf-8 equivalent of ChrW(8216) is " & _
Mid(strTemp, iStart, iEnd - iStart)
Else
MsgBox "Could not find utf-8 equivalent of ChrW(8216)"
End If
'******************************************************************************
Function XMLEncode(strEncodingType, strToEncode)
Dim strParam2, xmldoc, pi, e, sTemp
strParam2 = "version='1.0' encoding='" & strEncodingType & "'"
Set xmldoc = CreateObject("Microsoft.XMLDOM")
On Error Resume Next
Set pi = xmldoc.createProcessingInstruction("xml", strParam2)
If Err then
MsgBox "Error in function XMLEncode -- Quitting" & vbCrLf & _
"Encoding: " & strEncodingType & " " & Err.Description
WScript.Quit
End If
On Error GoTo 0
xmldoc.appendChild(pi)
Set e = xmldoc.createElement("test")
e.text = strToEncode
xmldoc.appendChild(e)
With CreateObject("Scripting.FileSystemObject")
sTemp = .GetTempName
If .FileExists(sTemp) Then
MsgBox "Quitting -- Temporary file name " & sTemp & _
"already in use."
WScript.Quit
End If
xmldoc.save(sTemp)
XMLEncode = include_AU(sTemp)
.DeleteFile(sTemp)
End With
'XMLEncode = xmldoc.documentElement.xml
End Function 'XMLEncode(strEncodingType, strToEncode)
'******************************************************************************
Function include_AU(sFileName)
'Return a string containing the entire contents of
' the specified file.
'First reads file as ASCII; if Byte Order Mark exists,
' (BOM = first two char FF FE), Reads file as Unicode.
Dim objFSO
Dim objTextStream
Dim objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFile = objFSO.GetFile(sFileName)
If Err then
Msgbox "Quitting - file " & sFileName & " can not be included."
Wscript.Quit
End If
On Error GoTo 0
'Read as ASCII
include_AU = objFile.OpenAsTextStream(1, 0).ReadAll
If left(include_AU, 2) = Chr(255) & Chr(254) Then
'Read as Unicode
include_AU = objFile.OpenAsTextStream(1, -1).ReadAll
End If
End Function 'include_AU(FileName)

-Paul Randall




"Arran" <Arran@discussions.microsoft.com> wrote in message
news:BE2AA4CC-7C14-48BA-9DFD-C091590835F8@microsoft.com...
>I am using windows 2003 server english version. I got the folloing message
> when I put a big5 code to CHR function to get a ANSI character
>
> Microsoft VBScript runtime (0x800A0005)
> Invalid procedure call or argument: 'Chr'
>
> I found that i cannot pass a number greater than 255 to the function. The
> code works before in windows 2000 server traditional chinese version. Is
> there any function/code I could use to translate a 2-bytes big5 code to
> utf-8
> code?
>