Solved

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

Posted on 2004-10-15
3
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

696 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