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
1ก35850E01d
2ข35860E02-
3ฃ35870E03]
4ค35880E048
5ฅ35890E05}
6ฆ35900E06S
7ง35910E07:
8จ35920E080
9ฉ35930E09C
10ช35940E0A^
11ซ35950E0B+
12ฌ35960E0CG
13ญ35970E0DP
14ฎ35980E0EE
15ฏ35990E0FD
16ฐ36000E10`
17ฑ36010E11R
18ฒ36020E12<
19ณ36030E13I
20ด36040E14f
21ต36050E159
22ถ36060E165
23ท36070E17m
24ธ36080E18T
25น36090E19o
26บ36100E1A@
27ป36110E1Bx
28ผ36120E1Cz
29ฝ36130E1D/
30พ36140E1Er
31ฟ36150E1Fa
32ภ36160E204
33ม36170E21,
34ย36180E22p
35ร36190E23i
36ฤ36200E24A
37ล36210E25[
38ฦ36220E26?
39ว36230E27;
40ศ36240E28L
41ษ36250E29K
42ส36260E2Al
43ห36270E2Bs
44ฬ36280E2C>
45อ36290E2Dv
46ฮ36300E2EV
47ฯ36310E2FO
48ะ36320E30t
49ั36330E31y
50า36340E32k

  … in-between has cut …
charDecHexkeyboard
81๑36650E51"
82๒36660E52#
83๓36670E53$
84๔36680E54%
85๕36690E55(
86๖36700E56)
87๗36710E57_
88๘36720E58=
89๙36730E59~
90๚36740E5A
91๛36750E5B


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

このサイトで扱った項目