Re: Opening a text file that may be ASCII *or* Unicode
- From: Andrew Aronoff <NOSPAM_WRONG.ADDRESS@xxxxxxxxx>
- Date: Sun, 19 Jun 2005 12:17:52 +0200
Since I can't find any documentation about TriStateUseDefault, I
decided to open the file in ASCII; read the first two characters;
close the file; compare those characters to 255 & 254; if true, open
in Unicode, otherwise open in ASCII.
Const ForReading = 1
Const TriStateFalse_ASCII = 0, TriStateTrue_Unicode = -1
'strFileName points to a text file in ASCII or Unicode
Set oTextFile = Fso.OpenTextFile (strFileName, ForReading, _
False,TriStateFalse_ASCII)
'read 1st 2 chrs, find Asc chr code
intAsc1Chr = Asc(oTextFile.Read(1))
intAsc2Chr = Asc(oTextFile.Read(1))
oTextFile.Close
If intAsc1Chr = 255 And intAsc2Chr = 254 Then
'open the file in Unicode
Set oTextFile = Fso.OpenTextFile (strFileName,ForReading, _
False,TriStateTrue_Unicode)
Else
'open the file in ASCII
Set oTextFile = Fso.OpenTextFile (strFileName,ForReading, _
False,TriStateFalse_ASCII)
End If
It's not elegant, but it seems to work.
regards, Andy
--
**********
Please send e-mail to: usenet (dot) post (at) aaronoff (dot) com
To identify everything that starts up with Windows, download
"Silent Runners.vbs" at www.silentrunners.org
**********
.
- Follow-Ups:
- Re: Opening a text file that may be ASCII *or* Unicode
- From: Joe Earnest
- Re: Opening a text file that may be ASCII *or* Unicode
- References:
- Opening a text file that may be ASCII *or* Unicode
- From: Andrew Aronoff
- Re: Opening a text file that may be ASCII *or* Unicode
- From: Andrew Aronoff
- Re: Opening a text file that may be ASCII *or* Unicode
- From: Miyahn
- Re: Opening a text file that may be ASCII *or* Unicode
- From: Andrew Aronoff
- Re: Opening a text file that may be ASCII *or* Unicode
- From: Miyahn
- Opening a text file that may be ASCII *or* Unicode
- Prev by Date: Re: Activating a macro when opening an Excel File
- Next by Date: Re: DateLastModified - Get Yesterday ONLY
- Previous by thread: Re: Opening a text file that may be ASCII *or* Unicode
- Next by thread: Re: Opening a text file that may be ASCII *or* Unicode
- Index(es):
Relevant Pages
|