Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-15
3
Medium Priority
?
446 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 1000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
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…
Suggested Courses

604 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