Japanese

Type Thai using VBA

Hear you can insert Thai characters in a Word document as you feel like keyboard touch. As VBA code used here is quite simple, you can readily alter to another language, for instance العربية Arabic and മലയാളം Malayalam languages.

Argorithm and Alteration

Fig.1 Thai keyboard

Table 1. Unicode and Characters
charDecHexkeyboard
135850E01d
235860E02-
335870E03]
435880E048
535890E05}
635900E06S
735910E07:
835920E080
935930E09C
1035940E0A^
1135950E0B+
1235960E0CG
1335970E0DP
1435980E0EE
1535990E0FD
1636000E10`
1736010E11R
1836020E12<
1936030E13I
2036040E14f
2136050E159
2236060E165
2336070E17m
2436080E18T
2536090E19o
2636100E1A@
2736110E1Bx
2836120E1Cz
2936130E1D/
3036140E1Er
3136150E1Fa
3236160E204
3336170E21,
3436180E22p
3536190E23i
3636200E24A
3736210E25[
3836220E26?
3936230E27;
4036240E28L
4136250E29K
4236260E2Al
4336270E2Bs
4436280E2C>
4536290E2Dv
4636300E2EV
4736310E2FO
4836320E30t
4936330E31y
5036340E32k

  … in-between has cut …
charDecHexkeyboard
8136650E51"
8236660E52#
8336670E53$
8436680E54%
8536690E55(
8636700E56)
8736710E57_
8836720E58=
8936730E59~
9036740E5A
9136750E5B


Fig.1 shows an example of Thai keyboard. Character number, Thai character, and corresponding Unicode number are listed in Table 1. The fifth column in the table is location of keyboard character.

Algorithm is quite simple, i.e. if you type "d", then ChrW(3585) ( ก : Ko-Kai 1st Thai character ) turns out at the selected position.

In practical use, phrases are touch-typed in "InputBox" and push Enter key.

   − to alter to another language −

Simply change variables "a" and "w", that's everything OK.

   − for example −

If let "a" and "w" variables as follow, you can type Malayalam language.

  a = 3330
    w = " x =  D E F R G T ~   Z S W   A Q k K i I U" & _
        " ; + p P { : * @ ` C l L o O v  h H y Y c / j J" & _
        " n N B b M < m u     e f r g t ^   z s w   a q d" & _
        "                   |      0 1 2 3 4 5 6 7 8 9         "

and if you change as follow

  a = 1548
   w = " K               P    ?  x N H c Y  h f m j e @ p o [  v . s a w q : / u" & _
     " y       t r ; g l  i , n d W R A Q E S                X   "

you can type Arabic characters. Characters may be inserted left wise.

  a = 1025
   W = " ?               F < D U L T + P B Q R K V Y J G H C N E A ` W X I O" & _
   " { S M * > Z f M d u l t ; p b q r k v y j g h c n e a @ w x i o [ s m : . z _ "

becomes Russian language.

  ==== Guide to prepare Original one ====

  − Create original Table −

Using Excel application, column 3 in Table 1. is newly prepared utilizing autofill technique. and column 4 are typed as 『 = dec2hex(c2) 』.

  − Create kAr() −

As it needs rather high technique to create variable "w", following description may be simpler and better.

kAr(1)="d": kAr(2)="-": kAr(3)="]": kAr(4)="8": kAr(5)="}": ……

In this case, the first line in VBA code must be changed as 『 Dim kAr(##) 』. and 『 kAr = Split(w) 』 is needed to delete. ( ## is an Unicode range: ## = 91 for Thai as shown in Table 1.)

Digression

Keyboard character may differ depending on computer machine, so if needed, Array variable "kAr()" must be changed.

『 .InsertAfter vbCr: .Start = .End - 1: .Delete 』 is only a dummy, in the absence of this description, characters do not appear unless closing InputBox.

If you use Excel application, lines 16 to 18 must be changed as follow.

ActiveCell.Value = s: ActiveCell.Range("a2").Activate


Sub typethai()
Dim kAr                  '== Word type Thai Ver. 3.2 =====                                 ' 1
w = " d - ] 8 } S : 0 C ^ + G P E D ` R < I f 9 5 m T o @ x z / r a 4 , p i A [ ? ; L" & _
  " K l s > v V O t y k e b u 7 n 6 &      ' g c F . w  q H j h U J N    Q " & Chr(34) & _
  " # $ % ( ) _ = ~ "                                                                 '4
 kAr = Split(w)                                                                              '5
  a = 3585: x = 100: y = 100: w = "The longest name of city": kAr(0) = "di6:gmrO"            '6
myLoop:                                                                                      '7
   s = InputBox(kAr(0) & " will turns out " & w & _
           vbCr & "Cansel for stop", "Type In", kAr(0), x, y)                                '9
      w = "same as befor": kAr(0) = s:   If s = "" Then End                                 '10
 
 
     For i = 1 To UBound(kAr)                                                               '13
         s = Replace(s, kAr(i), ChrW(a + i - 1))                                            '14
     Next                                                                                   '15
   With Selection                                                                           '16
     .InsertAfter Text:=s: .InsertAfter vbCr: .Start = .End - 1: .Delete                    '17
   End With                                                                                 '18
  GoTo myLoop                                                                               '19
End Sub

このサイトで扱った項目