Solved

capturing Chinese words and storing it in SQL

Posted on 2004-09-22
7
174 Views
Last Modified: 2010-05-02
i am working with chinese words for the purpose of sending chinese invoices overseas. i have one program which allows a user to input the chinese equivalent for items, and then order them in chinese to be sent overseas. this program where they input the items in chinese has stumped me a bit, with the conversions from ANSI to UNicode, etc.

I have a Unicode text box, where a user will enter the Chinese symbols, or English equivalent for an item. then they click a button which will save this value away in a table, (SQL Server). This is fine, but when i do save the chinese item name, VB converts it into a long, non-sensical string of characters.

My question is, how do i read the chinese item name in unicode from my unicode text box, without VB handling it, i.e. without it interferring with my value???
0
Comment
Question by:stromberg45
  • 4
  • 2
7 Comments
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 12129696
Try use M$ Form 2.0 Library, and make sure you use either nchar, nvarchar, ntext, etc to store your Chinese (unicode) characters

Useful info:
http://support.microsoft.com/default.aspx?scid=kb;en-us;193540
http:Q_20336162.html
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 125 total points
ID: 12129880
Strings in VB are unicode by design, i.e. each character is stored internally as two bytes.
If you have a unicode enabled control, like the Forms 2 TextBox, then you can read and write unicode characters without problems.

Example:
Project->Components->Microsoft Forms 2.0 Object Library

Place 2 (Forms 2) Text boxes on your form

Set the font for the textboxes  to "Gulim" or any other Chinese unicode set.

Input Chinese characters to the first textbox (I had to use charmap to do this) using a paste operation.

Then see that the string saved from the textbox is unicode, and that the Chinese content is preserved when writing to the second textbox.

You can store the string as a byte array and still retrieve the data w/o problems. (useful if SQL can't handle unicode)

Some code:

Option Explicit

Private Sub Command1_Click()
    Dim sInText As String
    Dim sOutText As String
    Dim aAscii() As Byte
   
    'Store the Unicode text
    sInText = TextBox1.Text
    'And save it as a byte array just for fun
    aAscii = sInText
    'Reload the byte array into a VB string
    sOutText = aAscii
    'Transfer the Unicode to the second textbox
    TextBox2.Text = sOutText
End Sub

Private Sub Form_Load()

    'These are Forms 2 controls
    'Gulim is a Simplified Chinese Unicode Font
    TextBox1.Font.Name = "Gulim"
    TextBox2.Font.Name = "Gulim"

End Sub


'Here's a beer, good night

0
 

Author Comment

by:stromberg45
ID: 12138757
this is how i was doing it before. the problem lies in the method i'm getting the value entered into the chinese text box into a string variable or byte array variable.

the fact is, when i say, string1=chinesetextbox.text, that value that is shown in chinesetextbox.text is just question marks, i.e. it is not in chinese anymore.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 32

Expert Comment

by:Erick37
ID: 12138847
I don't follow.

dim string1 as string '<< Make sure you specify string

string1 = chinesetextbox.text '<< get the text

chinesetextbox.text = string1 '<< this does not work?

Which unicode control are you using?

0
 

Author Comment

by:stromberg45
ID: 12139014
i'm using the Windows Form 2.0 Control Text Box.

I have installed the Chinese language through the Windows control panel.

When I'm in the Unicode text box (Form 2.0 control -- txtChinesetext), i change the computer's language to Chinese and type Chinese symbols, -- they display correclty, however when i save this value into table i firstly put this typed value into string.

dim sChineseItemName as String

sChineseItemName = Me.txtChinesetext.Text        'have tried Me.txtChinesetext.Value (same thing)

If i debug it, the value that is shown to be in -- Me.txtChinesetext.Text -- is just question marks, that is, I think VB is converting it back to ANSI, (or something) and it doesn't understand it.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12139638
"If i debug it, the value that is shown to be in -- Me.txtChinesetext.Text -- is just question marks"

Unless you have the Chinese or Simplified Chinese version of Visual Bas&#297;c, the immediate window (AKA debug window) and hover values in the VB IDE will not support full unicode text.  Even if you set the editor's font to a unicode font, any extended character codes display as ? (just like a standard TextBox).  If you need to debug.print your text, you can always add another form to your project and place a Forms2 textbox on it.  Name the form uDebug and write a function called uPrint which transfers the text to the Forms2 control.  Then to test your code, type uDebug.uPrint(txtchinesetext.Text).

However, VB strings are unicode strings, and you should have no problems reading from, storing, and retrieving the unicode text.  Just be aware that when passing VB strings to APIs or even some databases, you may need to send them as byte arrays to preserve the string as unicode.

Good luck!
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12255435
smart,funny?
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to open Waze.com/livemap from address saved in DB? 26 213
SSRS expression Issue finding a string 10 93
using web browser with BING 40 132
Hide vba in gp 7 106
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question