Display Vietnamese Unicode text in Access 2000

Have you ever had problems with Vietnamese Unicode in your Access applications? A problem that many readers encounter in Access 2000 (running on Win98), when executing the function to convert numbers to letters (for example, 123 to a hundred and twenty three) using Vietnamese Unicode when sending out the form is not displayed. Vietnamese.

Have you ever had problems with Vietnamese Unicode in your Access applications? A problem that many readers encounter in Access 2000 (running on Win98), when executing the function to convert numbers to letters (for example, "123" to "one hundred and twenty three") uses Vietnamese Unicode when sending the form. Vietnamese words cannot be displayed.

Before solving the problem we need to clarify some points. Usually Office 2000 uses VBA version 6.0 language to write code. On Win9x or WinMe, there are two drawbacks when using Unicode in programming to display Unicode strings on interface elements:

1. The VBA code editing environment does not allow you to enter correctly Unicode strings.

2. VBA standard version, version 6.0 does not display Unicode strings.

To overcome these two obstacles, you should:

1. Enter Unicode string in the interface design window and code editor window in UTF-8 format because this format is compatible with traditional ASCII code. Of course, before
When using UTF-8 string properly, you need to convert it to USC-2 format by calling the Windows API function named MultibyteToWideChar ().

2. Instead of using the available interface objects of the VBA design environment, you must use the corresponding Form2 objects. "Microsoft Form 2.0 Object Library" is a library of interface objects that Microsoft recently wrote to support the correct Unicode code.
We have written a simple form, there is a textbox to enter numeric values, a textbox to display the corresponding text string (in the simplest form, essential to illustrate the handling of Unicode strings), 1 button allows turning numbers into strings. The objects used are in the "Form 2.0" library. This application development process includes the following specific steps:

1. Because VB's Declare statement does not properly declare API functions with parameters that are Unicode strings, you must first build a type library (type library) containing the MultiByteToWideChar () function for use in the application. Use a text editor to compose the TypeLib library specification that contains the MultiByteToWideChar () function in the ODL language as follows (store the content on the uniutil.odl file):

[
uuid (13C9AF40-856A-101B-B9C2-04021C007002),
helpstring ("WIDE Windows API Type Library")
]
library WideWin32API
{
[
helpstring ("KERNEL API Calls"),
dllname ("KERNEL32")
]
module KernelAPI
{
[
helpstring ("Convert a UTF8 string to a UCS-2 string."),
entry ("MultiByteToWideChar")
]
long _stdcall MultiByteToWideChar
(
[in] long CodePage,
[in] long dwFlags,
[in] BSTR lpMultiByteStr,
[in] long cchMultiByte,
[in] BSTR lpWideCharStr,
[in] long cchWideChar
);
};
};

2. Translate the ODL file into an uniutil.tlb type library file using the mktyplib.exe utility. To get this utility, you can install Visual Studio 6.0, if you install in Typical mode, the VS will be installed in the "c: Program Files Microsoft Visual Studio" folder. If so, to translate the above uniutil.odl file, create a DOS Prompt window, use the cd command to return to the directory containing the uniutil.odl file, then enter the following two commands sequentially to translate it:

c: progra ~ 1micros ~ 3vc98binvcvars32.bat
mktyplib / I c: progra ~ 1micros ~ 3vc98include / win32 / tlb uniutil.tlb uniutil.odl

Suppose the short name of the "Program Files" folder is progra ~ 1, of the "Microsoft Visual Studio" folder is micros ~ 3.

3. Run VB, create 1 project "Standard Exe" to manage the application.

4. Right-click an empty spot in the ToolBox window, select "Components ." to display the "Components" window, click the Controls button, browse to "Microsoft Forms 2.0 Object Library" and select it to add the interface element in this library into Project VB's Toolbox.

5.Select Project.References menu . to display the References window, press the Browse button and browse the file system to select the uniutil.tlb file created in step 1 to add it to Project.

Display Vietnamese Unicode text in Access 2000 Picture 1Display Vietnamese Unicode text in Access 2000 Picture 1

6. Draw each element in turn: 1 TextBox has the attribute Name = txtSo; 1 Label combination with attribute Caption = "Please enter the number:"; 1 CommandButton has Caption = "Start transfer" attribute and attribute Name = cmdChuyenSo; Another TextBox has the attribute Name = txtChuoi; 1 Label combination has Caption = "Equivalent string:". Note that you must use the Vietnamese language support capable of creating UTF-8 code (VietKey 2000, GVSBK 2.2, .) and choose this code for entering Vietnamese strings while designing forms and writing code. Note also that the elements to be drawn are elements of the "Microsoft Forms 2.0 Object Library" library, rather than standard VB elements (usually they are at the bottom of the ToolBox window). After the design is complete, the form will have the following form (note the UTF-8 strings are difficult to read):

7. Create event handling procedure Click the cmdChuyenSo button and then enter the form's code writing window to enter the following program segment:

Option Explicit

'sequence contains UTF8 string describing the digits

'code signed 0 to 9 is 48 to 57

Dim dayUTF8 (48 To 57) As String

'sequence contains the string UCS2 describing the digits

Dim dayUCS2 (48 To 57) As String

'Procedure to start Form

Private Sub Form_Load ()

Dim s As String

Dim x () As Byte

Dim ret As Integer

Dim i As Integer

dayUTF8 (48) = "no"

dayUTF8 (49) = "one"

dayUTF8 (50) = "two"

dayUTF8 (51) = "three"

dayUTF8 (52) = "four"

dayUTF8 (53) = "year"

dayUTF8 (54) = "six"

dayUTF8 (55) = "seven"

dayUTF8 (56) = "eight"

dayUTF8 (57) = "nine"

'Transfer caption of cmdChuyenSo button to Unicode

x = StrConv (cmdChuyenSo.Caption, vbFromUnicode)

ret = MultiByteToWideChar (65001, 0, x, -1, s, 0)

s = Space (ret)

ret = MultiByteToWideChar (65001, 0, x, -1, s, ret)

cmdChuyenSo.Caption = s

'Convert caption of label lblSo to Unicode

x = StrConv (lblSo.Caption, vbFromUnicode)

ret = MultiByteToWideChar (65001, 0, x, -1, s, 0)

s = Space (ret)

ret = MultiByteToWideChar (65001, 0, x, -1, s, ret)

lblSo.Caption = s

'Switch the caption of label lblChuoi to Unicode

x = StrConv (lblChuoi.Caption, vbFromUnicode)

ret = MultiByteToWideChar (65001, 0, x, -1, s, 0)

s = Space (ret)

ret = MultiByteToWideChar (65001, 0, x, -1, s, ret)

lblChuoi.Caption = s

'Convert UTF8 strings to describe Unicode digits

For i = 48 To 57

x = StrConv (dayUTF8 (i), vbFromUnicode)

ret = MultiByteToWideChar (65001, 0, x, -1, s, 0)

s = Space (ret)

ret = MultiByteToWideChar (65001, 0, x, -1, s, ret)

dayUCS2 (i) = Left (s, Len (s) - 1)

Next i

End Sub

'click event handler function

Private Sub cmdChuyenSo_Click ()

Dim so () As Byte

Dim string As String

Dim i As Integer

chuoi = ""

so = StrConv (txtSo.Value, vbFromUnicode)

For i = 0 To Len (txtSo.Value) - 1

chuoi = chuoi & dayUCS2 (so (i)) & ""

Next i

txtChuoi.Value = chuoi

End Sub

When running, the form displays as follows (Unicode strings are displayed correctly):

Display Vietnamese Unicode text in Access 2000 Picture 2Display Vietnamese Unicode text in Access 2000 Picture 2

Nguyen Van Hiep

3.7 ★ | 3 Vote