Connecting Tech Pros Worldwide Forums | Help | Site Map

Read Unicode data from Text file

Chris
Guest
 
Posts: n/a
#1: Nov 9 '07
I am using the FileSystemOBject for writing text with Unicode as in
the example below. When I try to read data from the file with
ReadLine, I get "?????????" instead of characters with unicode.

What could be the problem ?

Thanks a lot in advance!

------------------------------------------------------------------------------------------------

Dim var_file_sys As Object
Dim var_txt_file
Dim var_line As String

Set var_file_sys = CreateObject("Scripting.FileSystemObject")
Set var_txt_file = var_file_sys.CreateTextFile(vn_export_file, True,
True)

var_txt_file.writeline (var_line)

var_txt_file.Close

------------------------------------------------------------------------------------------------

Const ForReading = 1, TristateTrue = -1
Dim var_f As Object
Dim var_text As string

Set var_file_sys = CreateObject("Scripting.FileSystemObject")
Set var_f = var_file_sys.GetFile(vnp_import_file)
Set var_txt_file = var_f.OpenAsTextStream(ForReading,
TristateTrue)

var_text = var_txt_file.ReadLine

var_txt_file.Close


Stuart McCall
Guest
 
Posts: n/a
#2: Nov 9 '07

re: Read Unicode data from Text file


"Chris" <CLarkou@gmail.comwrote in message
news:1194599649.145304.222170@57g2000hsv.googlegro ups.com...
Quote:
>I am using the FileSystemOBject for writing text with Unicode as in
the example below. When I try to read data from the file with
ReadLine, I get "?????????" instead of characters with unicode.
>
What could be the problem ?
>
Thanks a lot in advance!
>
------------------------------------------------------------------------------------------------
>
Dim var_file_sys As Object
Dim var_txt_file
Dim var_line As String
>
Set var_file_sys = CreateObject("Scripting.FileSystemObject")
Set var_txt_file = var_file_sys.CreateTextFile(vn_export_file, True,
True)
>
var_txt_file.writeline (var_line)
>
var_txt_file.Close
>
------------------------------------------------------------------------------------------------
>
Const ForReading = 1, TristateTrue = -1
Dim var_f As Object
Dim var_text As string
>
Set var_file_sys = CreateObject("Scripting.FileSystemObject")
Set var_f = var_file_sys.GetFile(vnp_import_file)
Set var_txt_file = var_f.OpenAsTextStream(ForReading,
TristateTrue)
>
var_text = var_txt_file.ReadLine
>
var_txt_file.Close
Not sure why it isn't working for you, but FWIW I msdr this test.vbs file,
and itworks perfectly. Maybe it'll give you a clue.

''' START CODE '''
Writefile
ReadFile

Sub Writefile
Set fso = CreateObject("Scripting.FileSystemObject")
Set a = fso.CreateTextFile("c:\temp\testfile.txt", -1, -1)
a.WriteLine("This is a test.")
a.Close
End Sub

Sub ReadFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\temp\testfile.txt", 1, 0, -1)
MsgBox f.ReadLine
f.Close
End Sub
''' END CODE '''


Chris
Guest
 
Posts: n/a
#3: Nov 9 '07

re: Read Unicode data from Text file


Thanks a lot Stuart for your message.

I could read the data from text file, the problem was appearing when I
had unicode characters (languages other than English). I was not able
to view the data read in VB, because ????????? were appearing, but
when I saved them in Access file, it seems to be ok.

Stuart McCall
Guest
 
Posts: n/a
#4: Nov 9 '07

re: Read Unicode data from Text file


"Chris" <CLarkou@gmail.comwrote in message
news:1194604652.684890.175430@o3g2000hsb.googlegro ups.com...
Quote:
Thanks a lot Stuart for your message.
>
I could read the data from text file, the problem was appearing when I
had unicode characters (languages other than English). I was not able
to view the data read in VB, because ????????? were appearing, but
when I saved them in Access file, it seems to be ok.
I must admit to hardly any knowledge of languages other than English, but
this problem of yours I find intriguing. Could you instruct me how to enter
some non-English characters so I may run a test or two? Do I simply switch
fonts?



Chris
Guest
 
Posts: n/a
#5: Nov 12 '07

re: Read Unicode data from Text file


Unfortunately I got the database from the country that entered the non-
english characters, I did not type them my self.

It seems to be working now, I use the OpenAsTextStream for reading
Unicode characters from TXT files and I insert them in an Access
database. Then I read the non-english characters from the Access
database for further processing.

Thanks a lot!!

Closed Thread