Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

How To Get Unicode Chars From Vb App Into A File

I've attached a file created in notepad and saved in the unicode format.

My requirement is that I want to be able to do this from within my vb application so I can take advantage of the 65k's worth of unicode charactors.

I've been wrestling with this for a day now and am at a stand still.

Can somebody make this easy for me?

I just want to be able to use some of those nifty chars that are beyond the 255 ascii's.
Nothing exotic.


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Get Unicode Chars Into A File
I know how to create a unicode file etc. but how do I get the chars that are above the 255 extended ascii into the file?

MyFile.WriteLine Str

for instance the "full block" charactor (hex 2588) which is part of the times new roman font.

What do I use for the 'value' of Str?


How To Get Unicode Chars From Vb App Into A File
I've attached a file created in notepad and saved in the unicode format.

My requirement is that I want to be able to do this from within my vb application so I can take advantage of the 65k's worth of unicode charactors.

I've been wrestling with this for a day now and am at a stand still.

Can somebody make this easy for me?

I just want to be able to use some of those chars that are beyond the 255 ascii's. Nothing exotic.


File System Object Does Not Recognise Unicode Chars..?
I just realised that fso.fileexists(path to the file) and it is there returns FALSE due to it having Unicode Chars..? like ό,ş,ϊ,ν,σ,ι

How can i get round this problem?

Display Unicode Chars.

i want to create an application in which user can choose any language(eg. Japnese, chinese etc). Based on that selecting user cna get required information in that particular language. This information in kept in access database. I have made a sample database in which i have inserted data in these languages. But in am unable to retieve this data as i am only getting ? (question marks) instead of those chars.

ny idea(s)..

Working With Unicode Chars
How can I store Unicode char in variable?

I would like to automate Office apps, eg. Excel and I need to put omega symbol and others into cells...
...if I copy it from charmap, it works. But if I try to record a macro, my nice omega is ? in code view and macro doesn't work.

Unicode Equivalent Of Chars
I want to convert the given data in it's unicode equivalent.
data can be in even french,jerman or telugu.
can any body please tell me what will be the process,function
or any other required tool.

Extending Textbox / Listview To Show Unicode Chars?
hi could someone tell me if it's possible to extend vb6 controls such as a textbox or listview to show unicode chars ( the one's that end up looking like ? ? 's ) ?

Replace Cyrillic Chars With Latin Chars
I've come pretty close to a solution on my problem with replacing all Cyrillic characters within a chosen area (cell, range, workbook....)
The only problem left now is that when I try to replace i.e. the Cyrillic letter "ћ" (unicode 045B) with the equivalent Latin letter ć (unicode 0107), the output is the letter c (without the acute).
From my VBA code I can see that I'm using the correct unicode for the letters, but it seems that no of the Latin Extended letters are able to be shown.
The same happens to the Latin letters ĉ, ċ and č. THey are all displayed as c.

What can I do to get the correct latin letter?

Write Chars Which Are Not Supported By Windows To A File
I have a problem to replace some content of my gdf file with Russian chars,,

firstly i read all the Russian chars to an array
secondly, read the content which will be replaced,
finally, write the Russian chars into files

the code is working ,,but My Problem is,
all the Russian chars in the new file are "???????"
how to slove the problem
i used string array to hold the Russian chars
should i use binary array??



Will Chars Make File Size Smaller
I would like to decrease memory useage and file size (I am writing out as binary). Ints are 4 bytes in VB6 right? How big are chars, and how big of a num can they hold? Or are shorts aviable, and how big are they? Thanks.

Adding Chars At The End Of Each Line Of A Text File
HI, i want to add two characters and the end of each line of a text file

For example ";;" :





I know its something with "nextline" (maybe) but
i didnt figure it out when i tried

HELP!how To Use VBA To Add Same Chars To A .txt File At Each Fixed Line Positions?
Hi, everyone!
Does anybody know how to add a "|" to each line at some fixed positions in a .txt file by excel VBA code?
for example, before in .txt file is:

And i want to let it be like this below:

NOTICE! not word by word, some "column" has more than one words...

Can anybody help me???THANK YOU IN ADV!!!

Search And Display Chinese Chars From Text File??
hi all, I need some help here...
If I have a text file database which is in unicode format:

xxxx [ yyyy ] yyyyyy
xxxx [ yyyy ] yyyyyy
xxxx [ yyyy ] yyyyyy
xxxx [ yyyy ] yyyyyy
xxxx [ yyyy ] yyyyyy

where x is chinese chars and y is english chars and each line is a new record

Q1) how do I display only a certain record from the textfile into a textbox?
Q2) how do I search for a specified part of the string eg. "yyyy" and display only the "xxxxx" which is chinese chars into the textbox and vice versa?

I need urgent help on this... thx...
so far i only managed to do this...

Private Sub Command1_Click()

Dim txtline As String

Open "xxxxx.txt" For Binary As #1

txtline = InputB(2, #1)

txtline = InputB(10, #1)

Close #1

TextBox1.Text = txtline

End Sub

Write Russian Chars To Text ( Html) File Aaaarghhh
hello ,, does someone know how i can acomplish the folowing task ,,

i have a program with a HTML interface and i need to write Russian chars to
the generated HTML files

my database is unicode ( access 2000 ) the characters in the database are
perfect however when they arive in vb and written to the text file they are
transformed to squares and other garbage

i was so desperate that i tried it on a Russian version of windows but same
thing happens there

if i use a VB form i can set the charset to a control and it will appear in
Russian however writing to a text file will result in garbage in the file
when i open it in Notepad or the webbrowser

strange thingy is if i look on a Russian website it appears OK , if i save
this file local to my system and open it with notepad it is also OK ( win
2000 advanced american english )

so the problem is probably that the string var that holds the data before it
is written to the text file mixes things up ???

how to solve this ???

How To Read Data From A File When The File Has 2 Byte Characters (UNICODE)?????
I want to read data from a file in which data is written in 2-byte characters (unicode). Actually i want to make a control that reads data from a file and writes the corresponding integer value (2-byte) to another file. This is easy in Visual C++ environment but in VB i am stuck. please help. I have very little time left to complete the task.

thanks in advance

Accepting Unicode Characters In Unicode Compliant Text Box In Vb 6.0
I want to develop ActiveX control using text box control from frm20.dll. This text box control is unicode complinat. When I enter unicode charaters in this text from VB, it displays extended characters and not the actual characters. But if I read from a text file where unicode characters are written, there characters are displayed properly. Also if I pase unicode text string from other application such as Word, these characters are also displayed properly.

I need some help in writing unicode characters in the text box directly.

Aparna Tamanekar

VB .NET - Unicode File I/O
I'm using VB .NET

1. Please tell me what functions do I use for converting ASCII text files to UNICODE?

2. what are the VB .NET functions for unicode file I/O?

3. If I have ListView control with some some text entries, how do I save them to file in particular encoding, say UTF-8?

I searched the forum, but I didn't find the answers to these questions...


Unicode File Name In VB6.0
Using common dialog, I'm trying to access files using non-English characters.

In case the characters language is not English and different from the regional settings default language, the file name returned by commondialog.filename is looks somthing like ?????.

Any idea how I can solve this problem?


Prevent Unicode Users From Running My Non-unicode App
I want to prevent users from running my app if their OS Unicode settings are going to cause trouble for my non-unicode aware VB6 app.

Anyone know a foolproof way to determine this?


Writing To A Unicode File
I have some problems using Excel and VBA for making a xml file. My problem is that if I use any of the Norwegian charaters; ζψε the table will not be displyed. If I how ever open the xml file in notepad an then save it using unicode it works.

I have tought of 3 posible solutions

1. Get the VBA code to save in unicode
2. Get the rest of the system - xsl file and html file to understand Norwegian charaters
3. Using VBA in Excel to open Notepad, open the XML file and then saving it in unicode.

I have no idea how to make any of this solution to work

To make the xml file I use the following code:
Sub leggut()
sti = Worksheets("verdier").Range("b1").Value
No_ark = Worksheets("verdier").Range("b3").Value
For a = 1 To No_ark
ark = Worksheets("verdier").Range("d" & a + 1)

Open sti + ark + ".xml" For Output As #1 ' Open file for output.
Print #1, "<PEOPLE>"

For x = 2 To Worksheets("verdier").Range("e" & a + 1).Value + 1

Print #1, "<PERSON>"

For y = 1 To Worksheets("verdier").Range("f" & a + 1).Value
z = Chr$(64 + y)
Print #1, "<" + Worksheets(ark).Range(z + "1") + ">" + Format(Worksheets(ark).Range(z & x)) _
+ "</" + Worksheets(ark).Range(z + "1") + ">"
Next y

Print #1, "</PERSON>"

Next x

Print #1, "</PEOPLE>"
Close #1

Next a

End Sub
Hope someone can help me with this


Manifest File And Unicode
I added a pretty standard manifest file into my project. I'm creating a button using CreateWindowExW to get Unicode support for it. After adding the manifest file the Unicode support is gone - anyone have a clue why? Is there anything wrong with the manifest I use?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="" processorArchitecture="x86" name="prjThemed" type="win32" />
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*" />

If I rename the manifest, everything is OK, except that the XP style is gone, but Unicode text displays correctly.

Saving A File As Unicode
how do I save a file as Unicode Text with VB?
The file is an XML file, I need to save it as XML file but Unicode Text.
I have a full path and I am working with FileSystemObject


Create Unicode File
I want to create a unicode file - and it works OK, EXCEPT it saves 2 codes at the start of the file :  FF FE  (only see them if you open with a HEX editor...

I saw in thread222-927492 (the only thread that was found when doing a search for "file FF FE" )
a remark that a Unicode file always starts with FF FE

but those 2 codes are exactly why the application that I am trying to feed fails.

if I can remove the FF FE I am fine.....

can I save the file differently and thus prevent that these 2 values are not added at the start ?

Unicode File Names
The post below by prasadmokashi's "GetWindowText API" got me thinking. I quickly stopped as it felt unnatural but it was too late......

If I had a Unicode enabled application and asked the user to enter a file-name and they entered it in Japanese. I then take that name and use it as a file name how would Windows handle the file name. DOS certainly would not be happy! I have a Linux box at home and it handles it fine (Hoorah) but I am not sure Windows would deal with it.

Writing To A Unicode File
I am creating a route for Microsoft Train Simulator. MSTS's Route Editor uses a Unicode marker file to display flags in the editor to mark the precise locations of objects (stations, switches, etc). Example:

Marker ( -81.5848 41.4792 SWoodland 2 )
Marker ( -81.5883 41.4835 Shaker/VanAken 2 )
Marker ( -81.5651 41.4809 LeeRd 2 )
Marker ( -81.5634 41.4807 BroxtonRd 2 )
Marker ( -81.5617 41.4804 WinthropRd 2 )
Marker ( -81.5598 41.4796 PaxtonRd 2 )
Marker ( -81.5584 41.4790 AttleboroRd 2 )
Marker ( -81.5561 41.4786 LitchfieldRd 2 )
Marker ( -81.5429 41.4785 CourtlandBlvd 2 )

I am writing a small VB6 program to download Waypoints from a GPS receiver and write them out to a marker file. Problem is, VB6 assumes the world revolves around ANSI. I can write out plain text no problem, but when I use the StrConv() function to convert those strings to Unicode and write them out I get an unprintable character following every single character written (see attachment), and the Route Editor will not read the file.

Wordpad has the capability of writing Unicode text, but I am growing weary of cutting and pasting hundreds of lines from one file to another. This program could save me tons of time if I could get it to work.

What (if anything) am I doing wrong (besides not upgrading to Visual Studio.NET)? I am using the default English/US code page.

Or should I just chuck the VB code and rewrite it in C++/MFC?

Your help is much appreciated.


Create File With Unicode Name
I have file with list of file names in number of different languages that I can read in my windows(2000). When I read the file name and try to create new file with this name it create like (??????.txt or 2#$@#%@.txt). How I can read unicode string and create file with unicode file name?

Help Required Unicode And .CSV File

When I write Chinese characters into a .CSV file , the characters appear as boxes. This is how I write..

Dim intFile As Integer

intFile = FreeFile
filename = Filepath & "" & filename
Open filename For Append As #intFile
Print #intFile, Text
Close #intFile

However if I use the fso and set the unicode file property to true, then the characters appear properly. But in this case, the delimiter comma is not recognised and all the data is written into single cell instead of seperating at commas..

Code for this is..

Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objStream As Scripting.TextStream

filename = Filepath & "" & filename

If Dir(filename) = "" Then
Set objStream = objFSO.CreateTextFile(filename, True, True)
Set objStream = objFSO.OpenTextFile(filename, ForAppending, False, TristateTrue )

End If

objStream.WriteLine (Text)

Can any body help me how to resolve this..



Unicode Enabling-File Handling
We a trying to unicode enable(provide support for Chinese,Japanese and Korean languages) a existing VB 6.0 application which involves reading and writing from ini/txt files.

I would like to know if
1. The are any known issues while reading/write unicode string to ini/txt files from VB 6.0

2. According to MSDN,the Print # statement puts data into a file as the data is displayed on the screen, in a locale-aware format.The Input # statement cannot read locale-aware data in Visual Basic that has been written to a file with the Print # statement. And its suggested that the Write # statement be used instead of Print#.
The problem is Write # statement prints double quotes to the file
Print #1,"Hello" 'Prints Hello into the file
Write #1,"Hello" 'Prints "Hello" into the file

Kindly clarify why Write # appends double quotes and if this would pose a problem while unicode enabling.

Thanks in advance

Read File With Unicode Character
Hi all :
I got a problem here. Is reading a file containing unicode character same with reading a normal file in VB6????Appreciate any comment or suggestion.

Save File As Unicode Text
does anyone know how to save a file as unicode text. i tried vbunicode on each string i wanted to save but the program i wrote it for doesn't read it. so after i save my file i have to manually open in wordpad and save it as unicode text doc. if anyone has any ideas please let me know.

Unicode Of Resource File Problem
Dear friends

Here I have a problem with Unicode and Resource file, thank you for your time and patient in advance.

I have an Excel File containing Chinese characters. Need to safely transfer those strings to an RES file. The RES already have some strings (other languages, not chinese) in it, all I need to do is to add them to RES file.

The problem is that all these Chinese characters change to ?? at client side (OS, English), even though it displayed okay at my place (OS, Chinese).

I did a lot of search online, and realized the problem is related to Unicode, ANSII and VB6’s Unicode and ANSII converting when put in and out from RES file.

Seems that I can’t just copy the Chinese characters from Excel file into clipboard, and paste them into RES file.

Would you please give me a hint, or explain for a few words ?
Really appreciate your help.

Haiyang Ai

Unicode File ..[ Resolved By BuggyProgrammer ]
Hi ,

After Long Search , I could not Find Any Usful Post regarding My Problem

When Download & Test the code , You Will Understand My Problem

* I can not Move , Copy or Delete a file written with an other Text Format (Font)

The File Name Created With Deffrent Languages

If I can Read the Extact Value for the The File name , that we be Fine

VB Code:
' --------------- MoudleOption ExplicitPublic Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" _(ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As LongPublic Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" _(ByVal lpFileName As String) As LongPublic Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" _(ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long'----------------  Option Explicit Dim fFound As String, TmpPath As String, NewPath As String Private Sub Form_Load() TmpPath = App.Path ' Application PathIf Right(TmpPath, 1) <> "" Then TmpPath = TmpPath & "" ' ;-)NewPath = TmpPath & "NewPath" ' The Target PathEnd Sub Private Sub MoveF_Click(Index As Integer) ' Array ! Text1.Text = ""fFound = Dir(TmpPath & "*.txt", vbNormal) ' Search for Text File *.txtDo Until fFound = "" ' Looping Until No *.txtText1.Text = fFound ' Show The Captured File NameDoEvents ' API Call to Move a fileIf Index = 0 Then MoveFile TmpPath & fFound, NewPath & fFound ' API CAll to Copy a FileIf Index = 1 Then CopyFile TmpPath & fFound, NewPath & fFound, 0 ' API CAll to Delete a FileIf Index = 2 Then DeleteFile TmpPath & fFound fFound = Dir() ' Get The Next File !Loop ' Go BackEnd Sub


Reading Unicode/binary File
The files that I am trying to read are composed of 3 parts. The first part is binary data (some unprintables, some not), the second part is unicode, and the third part is more binary data. These sections do not have a fixed size. The only part that I need to extract is the unicode (need to put in a string varible). I have come up with a scheme but it is slow........zzzzzz. I though someone might have some experience with this sort of thing.

Create A UNICODE Text File....
Hi all !!
Does anybody knows how to create a text file in UNICODE ?

I΄m using:
Open "file.txt" for Output as #1
Print #1, "Mytext"
Close #1

Help ?......

How To Read Unicode Text File ?
Please help me, because I can't find an easy solution to (someone could think) very simple problem.

I have a file that has Polish and Russian (cyrylic) characters. This text file is in unicode format, so I can see the text using notepad.

I have to read line by line (in fact this is csv file) and put the data into access database. The problem is, that I get "??????????" instead of Russian cyrylic. I read te file and put the string to textbox, I set the the textbox font properties to "cyrylic", but I still get "?????????????". I went through many tips of how to do it, but I always get question marks.

Now I'm using more less the following code to read the file and to get text line:

sub ReadUnicodeFile(pathToFile as string)

Dim myFSO, f, ts

Set myFSO = CreateObject("Scripting.FileSystemObject")
Set f = myFSO.GetFile(pathToFile)
Set ts = f.OpenAsTextStream(ForReading, _

'and now I put it into textbox to see the results

Do While Not ts.AtEndOfStream

    Text1.Text = ts.ReadLine

    msgbox "check what is in textbox" ' a moment to see magic question marks


end sub

I woul really appreciate any help. I also attached my test file with cyrylic if someone would like to play with it.


Write A File In Unicode Format.
How can I write a text file in unicode format? VB6 write ANSI format file by default ...... Its driving me crazy, can anyone help me out?

File Handling And Unicode Characters

1. I'm writing an application where I fetch data from a data base and write into text files. the data will contain local language characters like chinse, japanese etc. the application will be running in the multiple countries hence the code will be common to all countries. I would like to know if there will be any issue when i write these characters into the file. And how it should be handled? VB stores all the data in unicode format. Not sure what happens when it is written to the to the file?
do i need to take any special care in the vb code for local language characters?

2. I need a help in file handling too.

What is the best way to do file handling? Using File System Object(fso)
or using

Open FileName For Append As #1
Print #1, Text
Close #1

Before I write to the file, instead of writing field by field , I'm concatenating all the fields into a single string and pass this string for writing. This string would be a single line for me in the text file. Whats happening is ,the last field in the string is going to the new line. Any idea how this could be avoided? is there any buffer limit on the string?

3. One last help. I trigger the application from a UI. From the UI the selections made by the user is sent to the dll. I want to pass all the selections made at one shot to the dll and at the same time I want to show the progress status in the display bar in the form. Basically i want to raise an event from the dll at regular intervals and catch the event in the form? any pointers on this pls?

sorry for lots of questions

Thanks in advance

Convert A Unicode Text File To ASCII
I'm trying to read a text file into visual basic, change a part of it, and write it back out a text file. I had been having problems using OPEN (always resulted in an error 36), even though I had tried using LOF and EOF.

I found that the problem was the text file that I am trying to read from is in Unicode. Is there an easy way to convert this text file into an ASCII text file before I read from it?

Handling File Names Having Unicode Characters
I have a problem that I cannot seem to solve using any tips I have found on the net. I have a VB-program that asks the user for a file using the GetOpenFileNameW (W as in Wide, to support Unicode) API method.

The file selection works and I can, on an "English Windows" (its probably something else than the language that sets the limitation), recieve the file name and convert it back into a "VB-string". So, if the file name, for example, contains some Japanese Hiragana och Katakana characters, I can later open that file (using Scripting.FileSystemObject) using the "unicode file name". It seems to work for all characters I have tested.

Now to my problem: when testing the above on a machine running "Japanese Windows", some characters are suddenly not converted correctly. I have tried all sorts of workarounds, passing Locale ID to StrConv, using a UTF16toANSI() method I found on And so on...

No luck.

Here are the main pieces of my code:

Public Const OFN_CREATEPROMPT As Long = &H2000
Public Const OFN_EXPLORER As Long = &H80000
Public Const OFN_HIDEREADONLY As Long = &H4
Public Const OFN_LONGNAMES As Long = &H200000
Public Const OFN_NODEREFERENCELINKS As Long = &H100000


nStructSize As Long
hwndOwner As Long
hInstance As Long
sFilter As String
sCustomFilter As String
nCustFilterSize As Long
nFilterIndex As Long
sFile As String
nFileSize As Long
sFileTitle As String
nTitleSize As Long
sInitDir As String
sDlgTitle As String
flags As Long
nFileOffset As Integer
nFileExt As Integer
sDefFileExt As String
nCustDataSize As Long
fnHook As Long
sTemplateName As String
End Type


Public Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameW" (pOpenfilename As OPENFILENAME) As Long

Public Function BrowseForFile(StartupFolder As String, _
filePath As String, _
fileName As String) As Boolean
Dim NUL As String
Dim NULNUL As String
Dim retVal As Boolean
Dim sFullFileName As String

NUL = Chr$(0)

retVal = False

OFN.nStructSize = Len(OFN)
OFN.hwndOwner = 0
OFN.sFilter = StrConv("Test files" & NUL & "*.txt" & NULNUL, vbUnicode)
OFN.nFilterIndex = 1
OFN.sFile = StrConv(Space$(1024), vbUnicode) & NUL
OFN.nFileSize = Len(OFN.sFile)
OFN.sDefFileExt = NUL
OFN.sFileTitle = Space$(512)
OFN.nTitleSize = Len(OFN.sFileTitle)
OFN.sInitDir = StrConv(StartupFolder, vbUnicode)
OFN.sDlgTitle = StrConv("Open", vbUnicode)

If GetOpenFileName(OFN) Then

' Convert
sFullFileName = StrConv(OFN.sFile, vbFromUnicode)

sFullFileName above gets the correct value for all characters I have tested on English Windows. On Japanese Windows, some does not work and I do not understand why. I suspect it has something to do with the code page and/or locale but I cannot figure out how to solve it.

My code needs to run unchanged on all Windows locales.

Can someone point me in the right direction?

Unicode Output To UTF-8 Text File Problem
I can use the FM20.DLL control inside VB6 and the application can view / edit / add Simplified Chinese. However, when I export the data to a text file ,some Simplified character turned to ? instead of a valid Simplified Chinese

Value stored in the SQL2000 database is

When export to a notepad text file, it output as

I checked through the internet and the ADO data control 6.0 did support unicode and I think it is the problem when it output to the notepad which I use an array to hold the data, code as below
Dim o_Container
Open "ABC.TXT" for output as #1
o_Container(1) = adoh.recordset.fields("SimplifiedCharacter")
print #1, o_Container(1)
Print #1, adoh.recordset.fields("SimplifiedCharacter")
Close #1
'ABC.TXT contains
Where adoh.recordset.fields("SimplifiedCharacter") did hold the correct value "滁州市发生建市"

Thanks in advance

Simple Unicode File Reading Question
Hi all,
This issue seems to be easy BUT I can't make it work...

I am trying to read a file that is saved in Unicode(in Hebrew) and placing it's content on a label.
The problem is that I get gibberish letters on the caption instead of Hebrew...
I tried using strconv, no luck in that department...
And there is no apparent problem in the label font attr because while trying to insert hard coded Hebrew text on run time, the label shows the letters perfectly well.

Any suggestions from you geniuses out there ?

How To Open A File That Contains Unicode Characters (”‡A₯’†•ΆŽš) &lt; Chinese :S
How to open a file with unicode characters (in example ”‡A₯’†•ΆŽš) do i need to convert it to another format or something?

oh ok.. those characters should be chinese

Writing Unicode To Text File? [SOLVED]

Those who have read my previous posts know I'm currently trying to get Unicode working in my application. So far I've had some decent success, but now I've come across another problem.

There are a few places in my app where I use the Print # Statement to write to a text file. Unfortunately it seems this method does not support Unicode!

Is there a way I can write a text file in Unicode from within VB6?

Thanks in advance.

Edited by - SeanR on 5/8/2005 9:12:46 PM

Opening And Writing To A Text File In Unicode (VB6) - Possible?

I've written a program in Visual Basic 6 that loops through a list of words and writes them to a text file as the basis for a vocabulary learning game. However, I'm having problems with special accented characters like ä, é and so on, which are creating some strange results in the output file. They appear fine in the listbox.

I know this has something to do with Visual Basic 6 handling strings internally with Unicode, yet only writing to a file in the ANSI format. Is there any way to open a file for writing as UTF-8 or Unicode, or a way round this problem?

Hope someone can help - thanks!


Unicode To Non Unicode Conversion Problem
Hi All,

I am using C dll in macro which converts Unicode data to 8 bit encoding data
' Prototype of C function.
' extern "C" int _stdcall Uni2Eni(wchar_t * uni, unsigned char * eni, int size)

'Here is the function where creating alias of C function using C dll(capi.dll)
' ByVal Uni As String ( Its a Unicode string)
‘ByVal eni As String ( its a Non Unicode string)
Declare Function UNI2Eni Lib "capi.dll" Alias " Uni2Eni " ( ByVal Uni As String, ByVal eni As String, ByVal iSize As Integer) As Integer

Sub Test
Dim iRet as integer
Dim sEni as String
iRet = UNI2Eni(“佅”,sEni,40)
End Sub
On calling this function it return iRet =1 which shows conversion has been successful but the value returned in sEni is showing blank .
Is it the problem with data type or something else?
Please anyone can help me?.
I have used the same dll in open office macro .its gives right output in open office. So there is no question of wrong dll.

Help Required. Writing Unicode Characters Into Ascii File
Hi ,

I need a help in handling double byte characters( Japanese, Chinese kanji characters) and writing into an Ascii file.
My requirement is to write data into the file in fixed positions., Eg. col 1-40 will have one value, 41-72 will have another value and so on. The column positions are fixed for each value. If the value doesn't occupy the entire column width, then it has to be filled with blank spaces. For eg., if the col1 value is "Hello" then the remaining 35 positions will be filled with blank spaces.

Now suppose I write a Chinese/japanese character, then every character being a double byte character, it is supposed to occupy 2 positions. Suppose a string has 5 double bytes, then it is supposed to occupy 10 column positions in ascii file. Now because the col1 width is 40 , now I'm supposed to add only 30 blank spaces, otherwise it'll spill over into the next column.

( If the file opened with a proper code page , then it will show the actual characters, but if it is opened with a English code page, then you'll actually see these characters occupying 10 positions but all of them appear as junk.)

So in my VB code, I'm currently doing this:
First convert string into byte array,
Loop over byte array, and check if the character is a double byte or not.

(Because VB stores all characters as unicode, byte array would occupy the double the size of a string.
So if the character is a double byte, then both b(0) and b(1) to have value greater than 0.
If the character is a Ascii, then b(0) will have value greater than 0, but b(1) will be 0.
I checked the AscW value for these characters, some are greater than 255 and some have negative values also.)

b = myStr

For i = 0 To UBound(b) Step 2

If b(i + 1) <> 0 Then'Implies double byte character
NoOfDoubleByte = NoOfDoubleByte + 1
End If


then based on the no. of double bytes, reconstruct the string with appropriate no. of spaces.
Suppose the string is supposed to occupy positions 1-40, then decrement the No of double bytes in the string and add that many spaces.

mystr = mystr & space$(40-(len(mystr + NoOfDoubleByte ))

Then finally write this into an ascii file.

Open FileName For Append As #intFile
Print #intFile, myStr

Now the problem.
The logic appeared to work fine so far. But suddenly I find that there are some Japanese characters, though being double byte is appeared to occupy only one position,. ( When opened in note pad with a English code page , a few charaters have occupied 2 positions , but a few of them have occupied only one position.)
so this entire logic of building string has gone haywire. Can some one direct me to the correct way of handling this.

Any help is highly appreciated.



Need Quicker Read And Reformat Of Ascii|Unicode File Content
It started out as a simple routine that used the good ol' Input function to read the contents of a plain-text ASCII file into a string variable, applying a few simple sanity checks (limiting the returned string to a certain size, etc.)

Then it grew. First, it needed to not only return the original string, it had to chop up the string and return it as an array of individual lines (divided wherever a CR-LF delimiter was found). Then Unicode and other double-byte formats came into it, so it also needed to return the data as a byte array to keep it from getting corrupted.

The result is an inefficient monster that takes an inordinate amount of time to read any file that's larger than 10K or so. Go up to 64K, and you're looking at 5 seconds or more delay time. Terrible.

I've pounded around with various implementations of Input and InputB , tried StrConv without success, and even tried to get creative by using a hidden RTB for its .LoadFile method. The only working code I've come up with is the inefficient monster I just mentioned. Here's what it looks like.

The function returns all its data via this user-defined type:

VB Code:
Public Type FILEINFO    Error As Boolean       'File-reading error flag    Diag As String         'Error diagnostic string    Contents As String     'File contents as a single string    ContentsA() As String  'File contents as an array of lines (broken at CR-LF)    ContentsUA As Long     'Upper bound of the ContentsA array    ContentsB() As Byte    'File contents as a byte array    ContentsUB As Long     'Upper bound of the ContentsB arrayEnd Type

Here's the 'heart' of the function. Surrounding and within this code are the sanity checks that I mentioned above. "Split_Lines" is another function that searches the string for CR-LF delimiters and returns the string array.

VB Code:
Open File_Spec For Binary Access Read As #File_Num    'Assign array upper bound and re-dimension it    Retrieve_File.ContentsUB = LOF(File_Num)    ReDim Retrieve_File.ContentsB(Retrieve_File.ContentsUB) As Byte    'Read the contents of the file into the byte array and then close it.    For Loop_Index = 0 To Retrieve_File.ContentsUB        Retrieve_File.ContentsB(Loop_Index) = AscB(InputB(1, #File_Num))    Next Loop_Index    Close #File_Num    'Assign return values and exit.    Retrieve_File.Error = False    Retrieve_File.Diag = ""    Retrieve_File.Contents = ""    For Loop_Index = 0 To Retrieve_File.ContentsUB        Retrieve_File.Contents = Retrieve_File.Contents & Chr(Retrieve_File.ContentsB(Loop_Index))    Next Loop_Index    Retrieve_File.ContentsA() = Split_Lines(Retrieve_File.Contents)    Retrieve_File.ContentsUA = UBound(Retrieve_File.ContentsA)

Does anyone have any guidance on how to pare down this elephant, back into the mouse that it should be?

-- JDM

Is There Any Wany To Save ASCII Text File Into UNICODE Text File Thru VB6?
Hi there,

I have a text file in ASCII and I want to save this text file as UNICODE text file thru VB6. Is this possible from VB6, if so, please help me how to do this?

thanks in advance.

Convert From Unicode To Non-unicode In
Anyone knows how to? Need to use some vb6 style APIs that expect ascii only, null terminated strings.

Copyright © 2005-08, All rights reserved