Solved

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

Posted on 2004-10-15
3
398 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

778 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