Write Chinese chars to a text file using vbscript

蹲街弑〆低调 提交于 2019-12-01 21:38:12
Helen

Maybe it's got something to do with character encoding. Try directly specifying the Unicode format for the file in the last parameter of the OpenTextFile method:

Const Unicode = -1
Set outputFile = myFSO.OpenTextFile(getOutputName(Argument, getMsiFileName(Wscript.Arguments)), forWriting, True, Unicode)

Also, you need to close the file after writing to it:

outputFile.Close

If this doesn't help, try error handling like AnthonyWJones suggested.

Try this:-

MsgBox "Writing Line"
On Error Resume Next
outputFile.WriteLine s '' # Removed ( ) that shouldn't be there.
MsgBox "Err " & Err.Number & ": " & Err.Description
On Error GoTo 0

What do you get?

Things had changed along win versions. This works on Win10:

Set outputfile = myFSO.CreateTextFile(filename,True,True)

The 3rd arg is bool true/false for unicode/ascii 2. Surprisingly, when using myFSO.OpenTextFile the arg is int with 1 (not -1) for unicode 1.

Documentation:

https://msdn.microsoft.com/en-us/library/aa265018(v=vs.60).aspx

https://msdn.microsoft.com/en-us/library/aa265347(v=vs.60).aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!