johndavidson
11-30-2012, 08:47 PM
I have some code that reads an ASCII text file that I'd like to convert to reading a unicode text file. While the FileSystemObject permits writing of Unicode, the fso cannot be used to read it. The neatest solution I can think of would be to replace the existing code with a function that does the same using another method. Various sites suggest reading the file into a byte array, but that is beyond my skills. Has anyone got any code that will do this?
Here's my present piece of code:
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(p_strFilename) = False Then
p_params.FileLists = FileLists
p_params.Selections = Selections
p_params.SearchStrings = SearchStrings
Set fso = Nothing
Exit Sub
End If
Set tsIn = fso.OpenTextFile(p_strFilename) ' this reads an ASCII text file OK
' These result in “Invalid Procedure call or argument” and “Variable not defined”, respectively:
' Set tsIn = fso.OpenTextFile(p_strFilename, , , 1)
' Set tsIn = fso.OpenTextFile(p_strFilename, , , TristateTrue)
Do Until tsIn.AtEndOfStream
strLine = LTrim(tsIn.ReadLine)
strProperty = Left(strLine, 12)
strValue = Mid(strLine, 13)
If Left(strValue, 1) = " " Then
strValue = Mid(strValue, 2)
End If
strValue = Trim(strValue)
Select Case strProperty
Case etc.
Loop
Here's my present piece of code:
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(p_strFilename) = False Then
p_params.FileLists = FileLists
p_params.Selections = Selections
p_params.SearchStrings = SearchStrings
Set fso = Nothing
Exit Sub
End If
Set tsIn = fso.OpenTextFile(p_strFilename) ' this reads an ASCII text file OK
' These result in “Invalid Procedure call or argument” and “Variable not defined”, respectively:
' Set tsIn = fso.OpenTextFile(p_strFilename, , , 1)
' Set tsIn = fso.OpenTextFile(p_strFilename, , , TristateTrue)
Do Until tsIn.AtEndOfStream
strLine = LTrim(tsIn.ReadLine)
strProperty = Left(strLine, 12)
strValue = Mid(strLine, 13)
If Left(strValue, 1) = " " Then
strValue = Mid(strValue, 2)
End If
strValue = Trim(strValue)
Select Case strProperty
Case etc.
Loop