Today I would like to expose how to design, create and code a form in Visual Basic that supports two languages that are written in an opposite way. For example, I take Arabic and English. There will several constraints to overcome.
1. Arabic is written from right to left. By cons, English is written from left to right. This will require us to switch direction at each transition field US / AR.
2. The characters in both languages are completely different. Therefore the character table should be loaded at each transition as well. (Note that the Unicode standard can cover all these characters)
3. When typing, the manual switch between the two languages may be very inconvenient for the user.
4. The user should be typing and not using the mouse and other options.
We must therefore manage these constraints and give the user the best possible interface.
1. To do this, it would be wise to design the form into two parts. The right for Arabic and left for English.
2. Now we have to make sure that your program distinguishes the input fields language (corresponding to the TextBox, ListBox,….). Use the Tag property for each control to specify the input language (set it to ‘a’ for Arabic and ‘e’ for English).
NOTE: A good idea would be to create an indexed array of controls to make your coding easy.
3. Now select the Arabic controls and change the value of the RightToLeft option to True (this option is not available in older versions of VB). The typing will be from right to left.
4. The last thing to do is to ensure that once the user clicks in a control or the cursor gets into it, the language is set depending on the field tag.
We will need to create a module in which we define constants and the following procedure:
Declare Function ActivateKeyboardLayout Lib “user32” (ByVal HKL As Long, ByVal flags As Long) As Long
Declare Function GetKeyboardLayout Lib “user32” (ByVal dwLayout As Long) As Long
Global Const GlEnLang = 67699721 ‘ GetKeyboardLayout(0) vous permet d’obtenir le code
Global Const GlArLang = -265743359 ‘de la langue courante
Sub SwitchKeyboard(language As String)
Dim d As Long
d = 0
Select Case LCase(language)
d = ActivateKeyboardLayout(GlArLang, 0)
d = ActivateKeyboardLayout(GlEnLang, 0)
At this level, I think the above code is quite clear and it is not necessary to make comments.
5. Select a control and then double-click it and go to the GotFocus event. Insert the following code:
Call SwitchKeyboard(Left(fldText(Index).Tag, 1))
You just have to test your form now!
NOTE: For the connection to the database you can either link the fields to the DataSet in design mode or use the code to do it manually. I will not go into details as this may be the subject of another article. Indeed, we must configure the code pages in the database (and this depends on the DBMS used) to avoid having corrupted data.