Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function to convert Unicode to ascii

Status
Not open for further replies.

bslintx

Technical User
Apr 19, 2004
425
US
Hey all,

I have an HTA that parses out a application's lof file (dispatch.log). I can copy and paste manually to a text file and works great; however, it's wasn't my intention to have to do any "manual" copy/paste. I have looked(googled) and I saw a couple functions that by name seemed to be what I need; however, I still can't seem to get it to work.

Here's the process...please let me know if it's feasible or not...i certainly don't want to be chasing my tail if not...i'f up to any suggestions...it would be greatly appreciated (btw - somewhat of a vbs noob)

1. application creates a (unicode) log file (dispatch.log)
2. i need to "copy" the contents upon activating my .hta
and "convert" to an ascii text file (dispatch.txt)
3. the .hta currently has code to parse a text file with
no problems.
4. if i "read" directly from the log file i obviously get
errors since i am using fso

- ado, fso, combo? please advise...thanks
 
hi dm4ever,

i'm not sure what you mean by format w/ an fso object? i was able to get it to work...here is the code to do so...thanks for your time and quick response...

Code:
Function ReadBinaryFile(FileName)
  Const adTypeBinary = 1  
 
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")
  
  BinaryStream.Type = adTypeBinary  
  BinaryStream.Open  
  BinaryStream.LoadFromFile FileName
  
  ReadBinaryFile = BinaryStream.Read
End Function

 t = ReadBinaryFile("dispatch.log")

Function SaveTextData(FileName, Text, CharSet)
  Const adTypeText = 2
  Const adSaveCreateOverWrite = 2
  
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")
  
  BinaryStream.Type = adTypeText
  
  If Len(CharSet) > 0 Then
   BinaryStream.CharSet = CharSet
  End If
  
  BinaryStream.Open
  BinaryStream.WriteText Text
  BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function

SaveTextData "dispatch.txt", t, "us-ascii"


  Sub DisplayResults()
   set fso = Createobject("Scripting.FileSystemObject")

   set file = fso.opentextfile(path, 1)  
 
   aMigrationLogs = SPLIT(file.ReadAll, vbCrlf)

  file.close
  set file = nothing
  set fso = nothing

  ' ...code
 End Sub
 
If you look at the link you will see you can specify the format...unicode or ascii

Maybe try....

set file = fso.opentextfile("dispatch.log", 1,, True)

WScript.Echo file.ReadAll

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top