Re: VB - Ascii to Unicode and then Unicode to UTF-8 conversion (Very desperate!!)
- From: "Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 24 Oct 2006 18:38:12 +0100
If you have a mix of characters in your SQL Server table (i.e. Chinese and
Latin together) then you have to use a Unicode column type. This means using
nchar/nvarchar/ntext/etc rather than char/varchar/text.
Once you've read it into your VB6 program, using something like ADODB, then
you do not need to call 'IsUnicode (strDataRow)'. You can throw this
function away as the data will already be in Unicode. As I said earlier, all
VB6 String data is Unicode. If you want to confirm at this point whether
your data is correct, write out the individual character codes derived using
the AscW() function, not Asc(). AscW returns the real Unicode character
code, whereas Asc quietly converts the character argument to ANSI and
returns that code instead. If you simply try to display the String data in
the IDE then you may get "?" for Chinese characters, unless you have a full
Chinese installation.
Assuming that your String data has the correct Unicode character codes when
in memory, then the next thing to worry about is your CSV file. When writing
out data to a file using VB's Print statement, the Unicode String data is
converted to the current ANSI character set, and that's what is stored. If
you're currently running on a non-Chinese system then that means the data in
your CSV file will be wrong. I assume you know that ANSI character sets are
locale-dependent (e.g. 1252 for Latin-1, etc) whereas Unicode and UTF-8 are
locale-independent. This means that if you're creating your CSV file in a
Latin-1 locale (e.g. UK/US) and then sending it to a Chinese client, you
have to manually write out your data as UTF-8 (or Unicode). You cannot write
it out using Print and convert it later as the damage will already have been
done by then.
What software are your Chinese clients using to read these CSV files?
Tony Proctor
<maralikatti@xxxxxxxxx> wrote in message
news:1161699961.313492.242070@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi Tony,not be
Sorry for giving the half information...
I have a .EXE file which gets the data from SQL Server 2000 and writes
it to .CSV file, and later the .CSV file is sent to user via email.
This .EXE file is called from ASP front end, and this .EXE file is
written in VB 6.0
My SQL Server 2000 table is having "Chinese characters" which I'm
not able to display properly in .CSV file. So my Chinese users are
having problems with viewing their data.
I'm using below code to write the data to .CSV file
strFullPathFilename = strDestPath & strDestFilename
lngFileHandle = FreeFile()
Open strFullPathFilename For Append Access Write As #lngFileHandle
IsUnicode (strDataRow) ' --- Converts the data into UNICODE
Print #lngFileHandle, strDataRow
Close #lngFileHandle
Also I tried to set the .CSV file character set to UTF-8 like below..
Dim strBlockName As String
strBlockName = "Encode CSV File into UTF-8"
Dim SetChar
SetChar = "UTF-8"
With CreateObject("ADODB.Stream")
.Open
.LoadFromFile sPath ' Loads a File
.Charset = SetChar ' sets stream encoding (UTF-8)
.SaveToFile sPath, 2 ' adSaveCreateOverWrite
.Close
End With
Here my first question is..
1. Can it be done in VB6.0?
2. The data which I get from Oracle is in UNICODE or ASCII.. (my
assumption is data is in ASCII) And how to identify whether it is in
Ascii or Unicode?
3. Whether I need to change .CSV file character set to UTF-8 or I need
to change the data into UTF-8?
I tried lot of things.. and I was not able to solve this problem. I
will be thankful to you if you help me to solve this problem.
Thanks in advance. If you need any other info, please let me know.
~~Manju
Tony Proctor wrote:
Some questions Manju...
What do you mean by "one report"?
Where is your data coming from?
What do you mean by "not supporting Chinese"
VB always holdings String data in memory as Unicode. Hence, it should
from anecessary to perform an ANSI->Unicode conversion, unless you reading
tofile but then that should happen automatically. Also, why would you need
UTF-8generate UTF-8? Most UI controls want ANSI characters, not Unicode or
Tony Proctor
<maralikatti@xxxxxxxxx> wrote in message
news:1161636880.306352.281660@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi All,
I have one report which is not supporting Chinese characters, so now I
need to read each character present in ASCII and convert them to
UTF-8...
So I want ASCII to Unicode and Unicode to UTF-8 conversion in VB 6.0
Thanks a lot in advance.
~~Manju
.
- Follow-Ups:
- References:
- Prev by Date: Re: Creating a Standalone .exe File
- Next by Date: Re: Editing MP3 tags
- Previous by thread: Re: VB - Ascii to Unicode and then Unicode to UTF-8 conversion (Very desperate!!)
- Next by thread: Re: VB - Ascii to Unicode and then Unicode to UTF-8 conversion (Very desperate!!)
- Index(es):
Relevant Pages
|