Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a Unicode File 1

Status
Not open for further replies.

Brent113

Programmer
Aug 13, 2003
67
US
I need to read a unicode file line by line. I have everything set up except the code that converts the unicode to ansi. I have tried using the API call WideCharToMultiByte but it has too many parameters and I have no clue how to make it work.

The unicode file is a reg file. What do I need to convert it?

____________________________________________________________________________
There are only 10 types of people in the world. Those that know binary and those that don't

Brent
 
Hi Brent,

here's the FSO version for reading a Unicode text file:
Code:
Sub OpenTextFileTest
    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Dim fs, f
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile("c:\testfile.txt", ForAppending,[b]TristateTrue[/b])
    f.Write "your text"
    f.Close
End Sub

The crucial part is the "Tristate" property bolded in the code. It lets you specify that this is a Unicode file.

Cheers,
Andy

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
FYI -
The FSO object only knows UTF-16 style Unicode. It doesn't know UTF-8.

For that, you'll have to open & read the file using the Win32 APIs (CreateFile and ReadFile). To convert it into something that VB can understand, you'll have to call the MultiByteToWideChar API. I've never had any luck using it from VB either (it seems to work for other people -- just not me). I ended up putting it in an ATL C++ dll and calling it from VB that way.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
I was using the FSO to read the files in the first place, so it was a piece of cake to go back and add one constant. I tried it and it worked beautifully! Thanks!

____________________________________________________________________________
There are only 10 types of people in the world. Those that know binary and those that don't

Brent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top