Solved

How to convert an ANSI stream to Unicode using Windows Script Host

Posted on 2004-10-15
3
393 Views
Last Modified: 2008-02-01
Hi,
I am attempting to read text from an Ansi file into a Unicode file via Windows Script Host and am unsuccessful. The text is added, but it appears as non-readable characters. Any ideas? The code is posted below:

Sub MergeFile(OpenFile, AppendFile)
'reads file line by line & then merges
      Dim oOpen      'File object for source file
      Dim      oAppend      'File object for destination file
      Const FORREADING = 1
      Const FORAPPENDING = 8
      Const TRISTATETRUE = -1
      If NOT oFSO.FileExists(OpenFile)Then
            Exit Sub
      Else
            Set oOpen = oFSO.OpenTextFile(OpenFile, FORREADING)
      End If
      
      Set oAppend = oFSO.OpenTextFile(AppendFile, FORAPPENDING, TRISTATETRUE)
            
      Do Until oOpen.AtEndOfStream
      oAppend.WriteLine oOpen.Readline            ' Writes line to new file
      Loop
      oAppend.WriteLine "Comment=Test" &chr(34) &chr(34)
      oOpen.Close
      Set oOpen = Nothing
      oAppend.Close
      Set oAppend = Nothing
End Sub
0
Comment
Question by:optikon44
3 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 250 total points
ID: 12322371
try

Set oAppend = oFSO.OpenTextFile(AppendFile, FORAPPENDING, false, TRISTATETRUE)
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12322505
You can also explicity convert it to unicode:

oAppend.WriteLine StrConv(oOpen.Readline, vbUnicode) ' Writes line to new file
0
 

Author Comment

by:optikon44
ID: 12322910
Erick37, thanks for the tip but since I am using vbscript via WSH, I'm unable to use the strconv function. Eddykt's solution worked. Turns out I didn't have TRISTATETRUE in the correct position.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now