I have a vbscript (see below) that works fine when Regional Options
are set to English (US). However, if I change the Regional Options to
Chinese (PRC), the script fails with the following error message:

Test.vbs(20, 4) Microsoft VBScript runtime error: Invalid procedure
call or argument

The statement that fails is
f=2EWrite(msg)

The value of msg is " starting on 2007=E5=B9=B44=E6=9C=882=E6=97=A5 xxx"

As a workaround, I can get the script to work by changing
FormatDateTime(now(),1)
to
FormatDateTime(now(),4) ' -- returns a date in short format w/o
chinese characters

However, I am wondering if there is a way of making the script to work
with the long date format. Does anyone know why the long format
cause this problem? Is it because latin digits are mixed with chinese
characters?

I see the problem on both XP SP2 and Win 2003 SP1.

Thanks for any suggestion.

HH

Here is the actual script:


'--------------------------------------------------------------------------=
------------------------
Const ForReading =3D 1, ForWriting =3D 2, ForAppending =3D 8
Const OutFile =3D "c:\testfile.txt"

Dim fso, f, msg

Set fso =3D CreateObject("Scripting.FileSystemObject")

if fso.FileExists(OutFile) Then
fso.DeleteFile(OutFile)
End If

Set f =3D fso.OpenTextFile(OutFile, ForWriting, True)
msg =3D " starting on " & FormatDateTime(now(),1) & " xxx"
FormatDateTime(now(),4) & "." & vbCrLf
WScript.Echo "msg type is " & TypeName(msg)
WScript.Echo msg

f.Write(msg)
f.Close
'--------------------------------------------------------------------------=
------------------------

Re: script fails if string contains chinese characters by adamsigel

adamsigel
Mon Apr 02 15:35:46 CDT 2007

You need to open the text stream in Unicode mode.

Try changing the line to read:
Set f = fso.OpenTextFile(OutFile, ForWriting, True, -1)

Reference: http://www.cnsdn.com.cn/learn/index.asp?url=/learn/File.asp?FileID=395



Re: script fails if string contains chinese characters by drip37070

drip37070
Tue Apr 03 08:27:16 CDT 2007

Thank you!! Indeed, this fixes the problem.
HH

On Apr 2, 4:35 pm, adamsi...@gmail.com wrote:
> You need to open the text stream in Unicode mode.
>
> Try changing the line to read:
> Set f = fso.OpenTextFile(OutFile, ForWriting, True, -1)
>
> Reference:http://www.cnsdn.com.cn/learn/index.asp?url=/learn/File.asp?FileID=395