Richard
Richard

Reputation: 1501

VBScript: Printing all characters in UTF-8

I'm writing a simple script to build a HTML page to check if all the characters in UTF-8 are being rendered properly:

Dim oStream : Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.CharSet = "utf-8"

' Code writing out the top HTML snipped for brevity

Dim iChar
For iChar = 32 to 255
    oStream.WriteText iChar & " = " & Chr(iChar) & "<br/>" & VbCrLf
Next

' Code writing out the bottom HTML snipped for brevity

oStream.SaveToFile "page.html", 2
Set oStream = Nothing

This works great, until I try and print characters beyond 255 in which case I get the error: Invalid procedure call or argument: 'Chr' (800A0005).

Can someone please explain how I can print all the characters within the UTF-8 character set?

The test is designed to see how the raw characters renders - so having a file with &#256; in it would not be a correct as it would need to print the actual Latin capital letter A with macron (Ā).

Upvotes: 2

Views: 2539

Answers (1)

Alex K.
Alex K.

Reputation: 175766

You want the ChrW() variant;

ChrW is provided for 32-bit platforms that use Unicode characters. Its argument is a Unicode (wide) character code, thereby avoiding the conversion from ANSI to Unicode.

Upvotes: 4

Related Questions