Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

23 Experts available now in Live!

Get 1:1 Help Now