www.infralib.com

www.infralib.com
Please visit my new site http://www.infralib.com for my and other authors' newer posts, articles. We will also have forums, videos, webcasts and etc.
Showing posts with label VBScript. Show all posts
Showing posts with label VBScript. Show all posts

Friday, 1 July 2011

VBScript : OpenTextFile Weird/Bad Characters

I have just experienced a problem while trying to read a text file by vbscript. When I echo lines to screen I saw an empty line shows ÿþ, and other weird/bad characters.


Than I realized the problem is about the file's encoding. The text file I was trying to read is created by printing characters to a file. (dir c:\test.txt).

So don't forget to define encoding type while opening a file, check the three parameters below that you will use as a paramater for OpenTextFile

Open Using System Default > TristateUseDefault =-2
Open File As Unicode icin > TristateTrue=-1
Open File As ASCII icin > TristateFalse=0

Example:

Const ForReading = 1
Const TristateUseDefault=-2
Dim objFSO
Set objFile = objFSO.OpenTextFile("C:\WDSPendingDevices.txt", ForReading, True, TristateUseDefault)