Working with UNICODE in Visual Basic 6.0

By Siddharth Barman

 

Overview

Though the server based products like Windows NT and Windows 2000 offer full support for UNICODE, Win9X range of operating systems have failed to show even minimum support for this new standard.

 

This however does not mean that if you develop applications that target the Windows NT / 2000 operating systems, the application will be fully compatible with UNICODE. This is specially true for applications that have been developed using Visual Basic.

 

This exercise has been carried out to determine the problem areas that one would probably encounter when developing an International application using Visual Basic 6.

 

For applications that are being built from scratch, the problem would be of a lesser magnitude. However, if we want to have internationalization features in an existing application, a lot of revamping will be required to the existing code.

 

User Interface

The first step one must take in order to work with UNICODE is never to use Visual Basic’s intrinsic controls. Instead, use the Form 2.0 controls. This approach also may have its own problems. The application may be using certain third party controls for which there is no equivalent UNCODE version. This would pose a big problem to the development team. It is always safer to use the Forms 2.0 controls for standard user interface. If you do require any third party controls, make sure they support UNICODE.

 

Database Interaction

Most Visual Basic applications communicate with backend products like SQL Server using ActiveX Data Objects (ADO). ADO fully supports UNICODE because COM itself fully supports UNICODE. It always advisable to make use of Ado’s support for inserting, modifying & selecting capabilities to store and retrieve data and from backend databases. If existing code is written in a way that makes use of raw SQL statements, make sure all UNICODE texts are prefixed with a N.

 

e.g. insert into student values(N’Siddharth’, N’Barman’)

 

Another important point to note would be, UNICODE strings cannot be stored in a standard Char or VarChar database column. You should always declare a nChar or an nVarChar column. SQL Server has an nChar / nVarChar type. Other database systems would support UNICODE, however using a different type name.

 

Controls texts and captions

Even after using Forms 2.0 controls, it is difficult to work with UNICODE text at the code level. Therefore it is recommended, that all language versions of all controls and displayable text should be stored in a database of a UNCODE text file from where the displayable can be picked up and the user interface captions / text can be set. Have a database approach also allows flexible additions of new languages to the application.

 

 

.NET, the solution?

.NET languages like VB.NET, C# and VC++.NET have full support for UNICODE. If possible, it is always recommended to upgrade to the new versions of the respective language.


 A working example

Click here to download the Visual Basic 6.0 project.

To run this project, you will need:
1. SQL Server 2000 Database Server
2. Visual Basic 6.0
3. You should also install the Japanese Language Pack. To install a Language Pack, go to Control-Panel, Regional Options. Place a check-mark on the language that you wish to support. You will require Windows Installation CD to comeplete the language pack installation.

The Project Files:

SQL Server DB.sql Run this file using SQL Server Query Analyzier. It will create a database called VBUnicodeEx.
sqldata After creation of the database and the table(s) are complete, use the "Restore Database" function of SQL Server to populate the table(s). To invoke the Restore Database function, start SQL Server Enterprise Manager, navigate to your database, right click on the database and select "Restore Database" from the "All Tasks" menu.
Settings.ini Edit this file to reflect your SQL Server UserId and Password. e.g.
"Server=LocalHost;Driver={SQL Server};UID=sa;PWD=;Initial Catalog=VBUnicodeEx"
Unicode.vbp This is the main Visual Basic 6.0 project file. Compile it and run the the program.