Skip to content

Instantly share code, notes, and snippets.

@touchiep
Last active February 18, 2024 09:21
Show Gist options
  • Save touchiep/5a51834e6159f78022dc71d53f1ec59f to your computer and use it in GitHub Desktop.
Save touchiep/5a51834e6159f78022dc71d53f1ec59f to your computer and use it in GitHub Desktop.
[VBA][Excel] Convert Number to Words in many languages base on Thai coding. Language supports in this code: Thai, Lao, Japanese, Korean, Chinese, Burmese, Khmer and Vietnamese.
Function W2U(iText As String)
'Convert Words to unicode number of character
Dim N, AllChar
For N = Len(iText) To 1 Step -1
AllChar = AscW(Mid(iText, N, 1)) & " " & AllChar
Next
W2U = AllChar
End Function
Function U2W(iCode) As String
'Convert Unicode number to words
Dim N, AllChar, str, ns()
str = Split(iCode, " ", , vbTextCompare)
ReDim ns(UBound(str))
For N = UBound(str) To 0 Step -1
If IsNumeric(str(N)) Then
ns(N) = CLng(str(N))
AllChar = ChrW(ns(N)) & AllChar
End If
Next
U2W = AllChar
End Function
Function ThaiNSound(ByVal sNum, Optional NavyFormat As Boolean = False, Optional sFormat As String = "", Optional NewForm As Boolean = False)
'Thai Number Sound 2.4
'by Pongsathorn Sraouthai
'for use with long number only, if it was decimal, it will displaying as integer.
'NavyFormat = True: Use "หนึ่ง" as "เอ็ด" Default is False
'sFormat: If use any text, it will use as separator between place
'NewForm = True: use "เอ็ด" as "หนึ่ง" only in ten place. Default is False
Dim AllChar As String
Dim NumChar As String
Dim ColChar As String
Dim ColNum As Long
Dim N
Dim nPos As Long
Dim nStr As String, nDec As String
ColNum = 0
'Check if decimal number
nPos = InStr(1, sNum, ".", vbTextCompare)
If nPos >= 2 Then
nStr = Mid(sNum, 1, nPos - 1)
sNum = nStr
End If
If Len(sNum) > 15 Then Exit Function
For N = Len(sNum) To 1 Step -1
ColNum = ColNum + 1
Select Case Mid(sNum, N, 1)
Case Is = "0"
If val(sNum) = 0 Or sNum = "" Then
NumChar = U2W("3624 3641 3609 3618 3660") '"ศูนย์"
Else
NumChar = Empty
End If
Case Is = "1"
Select Case NewForm
Case False
If Len(sNum) >= ColNum And ColNum = 14 Or ColNum = 8 Or ColNum = 2 Then
NumChar = Empty
ElseIf ColNum = 13 Or ColNum = 7 Or ColNum = 1 Then
If NavyFormat = True Then
NumChar = U2W("3627 3609 3638 3656 3591") '"หนึ่ง" '2.51
Else
If Len(sNum) > ColNum And val(sNum) > 10 Then
NumChar = U2W("3648 3629 3655 3604") '"เอ็ด" '2.51
Else
NumChar = U2W("3627 3609 3638 3656 3591") '"หนึ่ง"
End If
End If
Else
NumChar = U2W("3627 3609 3638 3656 3591") '"หนึ่ง"
End If
Case True
If Len(sNum) >= ColNum And ColNum = 14 Or ColNum = 8 Or ColNum = 2 Then
NumChar = Empty
ElseIf Len(sNum) > ColNum And ColNum = 13 Or ColNum = 7 Or ColNum = 1 Then
If NavyFormat = False Then
If val(sNum) > 100 And Left(Right(sNum, 2), 1) = "0" Or val(sNum) > 100000000 And Left(Right(sNum, 9), 1) = "0" Or val(sNum) > 100000000000000# And Left(Right(sNum, 13), 1) = "0" Then
NumChar = U2W("3627 3609 3638 3656 3591") '"หนึ่ง"
Else
NumChar = U2W("3648 3629 3655 3604") '"เอ็ด" '2.51
End If
Else
NumChar = U2W("3627 3609 3638 3656 3591") '"หนึ่ง" '2.51
End If
Else
NumChar = U2W("3627 3609 3638 3656 3591") '"หนึ่ง"
End If
End Select
Case Is = "2"
If ColNum = 14 And Len(sNum) >= 14 Or ColNum = 8 And Len(sNum) >= 8 Or ColNum = 2 And Len(sNum) >= 2 Then
NumChar = U2W("3618 3637 3656") '"ยี่" '2.5
Else
NumChar = U2W("3626 3629 3591") '"สอง" '2.5
End If
Case Is = "3"
NumChar = U2W("3626 3634 3617") '"สาม"
Case Is = "4"
NumChar = U2W("3626 3637 3656") '"สี่"
Case Is = "5"
NumChar = U2W("3627 3657 3634") '"ห้า"
Case Is = "6"
NumChar = U2W("3627 3585") '"หก"
Case Is = "7"
NumChar = U2W("3648 3592 3655 3604") '"เจ็ด"
Case Is = "8"
NumChar = U2W("3649 3611 3604") '"แปด"
Case Is = "9"
NumChar = U2W("3648 3585 3657 3634") '"เก้า"
End Select
'case 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1
' ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ หน่วย
Select Case ColNum
Case Is = 1
ColChar = Empty
Case Is = 2, 8, 14
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("3626 3636 3610") '"สิบ"
End If
Case Is = 3, 9, 15
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("3619 3657 3629 3618") '"ร้อย"
End If
Case Is = 4, 10
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
ElseIf sFormat <> "" Then
ColChar = U2W("3614 3633 3609") & sFormat
Else
ColChar = U2W("3614 3633 3609") '"พัน"
End If
Case Is = 5, 11
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("3627 3617 3639 3656 3609") '"หมื่น"
End If
Case Is = 6, 12
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("3649 3626 3609") '"แสน"
End If
Case Is = 7, 13
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
ElseIf sFormat <> "" Then
ColChar = U2W("3621 3657 3634 3609") & sFormat
Else
ColChar = U2W("3621 3657 3634 3609") '"ล้าน"
End If
If Len(sNum) > 7 Then ColChar = U2W("3621 3657 3634 3609") '"ล้าน"
If Len(sNum) > 7 And sFormat <> "" Then ColChar = U2W("3621 3657 3634 3609") & sFormat
End Select
AllChar = NumChar & ColChar & AllChar
Next N
ThaiNSound = AllChar
End Function
Function LaoNSound(ByVal sNum, Optional sFormat As String = "") As String
'Lao Number Sound 1.0 (Developed from Thai)
'by Pongsathorn Sraouthai
'for use with long number only, if it was decimal, it will displaying as integer.
'sFormat: If use any text, it will use as separator between place
Dim AllChar As String
Dim NumChar As String
Dim ColChar As String
Dim ColNum As Long
Dim N
Dim nPos As Long
Dim nStr As String, nDec As String
Dim ds(0 To 17) 'digit static text
If sFormat <> "" Then
sFormat = " " & W2U(sFormat)
ds(14) = U2W("3742 3761 3737" & sFormat) 'พัน
ds(16) = U2W("3749 3785 3762 3737" & sFormat) 'ล้าน
ds(17) = U2W("3733 3767 3785" & sFormat) 'พันล้าน
Else
ds(14) = U2W("3742 3761 3737") 'พัน
ds(16) = U2W("3749 3785 3762 3737") 'ล้าน
ds(17) = U2W("3733 3767 3785") 'พันล้าน
End If
ds(0) = U2W("3754 3769 3737") '0
ds(1) = U2W("3804 3766 3784 3719") '1
ds(2) = U2W("3754 3757 3719") '2
ds(3) = U2W("3754 3762 3745") '3
ds(4) = U2W("3754 3765 3784") '4
ds(5) = U2W("3755 3785 3762") '5
ds(6) = U2W("3755 3771 3713") '6
ds(7) = U2W("3776 3720 3761 3732") '7
ds(8) = U2W("3777 3739 3732") '8
ds(9) = U2W("3776 3713 3771 3785 3762") '9
ds(10) = U2W("3754 3764 3738") '10
ds(11) = U2W("3776 3757 3761 3732") 'x1 เอ็ด
ds(12) = U2W("3722 3762 3751") '20 ซาว
ds(13) = U2W("3758 3785 3757 3725") 'ร้อย
ds(15) = U2W("3777 3754 3737") 'แสน
ColNum = 0
'Check if decimal number
nPos = InStr(1, sNum, ".", vbTextCompare)
If nPos >= 2 Then
nStr = Mid(sNum, 1, nPos - 1)
sNum = nStr
End If
If Len(sNum) > 15 Then Exit Function
For N = Len(sNum) To 1 Step -1
ColNum = ColNum + 1
Select Case Mid(sNum, N, 1)
Case Is = "0"
If val(sNum) = 0 Or sNum = "" Then
NumChar = ds(0)
Else
NumChar = Empty
End If
Case Is = "1"
If ColNum = 14 Or ColNum = 11 Or ColNum = 8 Or ColNum = 5 Or ColNum = 2 And Len(sNum) >= ColNum Then
NumChar = Empty
ElseIf ColNum = 13 And Len(sNum) > ColNum Or _
ColNum = 10 And Len(sNum) > ColNum Or _
ColNum = 7 And Len(sNum) > ColNum Or _
ColNum = 4 And Len(sNum) > ColNum Or _
ColNum = 1 And Len(sNum) > ColNum Then
If Mid(sNum, Len(sNum) - ColNum, 1) = 0 Then
NumChar = ds(1)
Else
NumChar = ds(11)
End If
Else
NumChar = ds(1)
End If
Case Is = "2"
If ColNum = 14 Or ColNum = 11 Or ColNum = 8 Or ColNum = 5 Or ColNum = 2 And Len(sNum) >= ColNum Then
NumChar = Empty
Else
NumChar = ds(2)
End If
Case Is = "3"
NumChar = ds(3)
Case Is = "4"
NumChar = ds(4)
Case Is = "5"
NumChar = ds(5)
Case Is = "6"
NumChar = ds(6)
Case Is = "7"
NumChar = ds(7)
Case Is = "8"
NumChar = ds(8)
Case Is = "9"
NumChar = ds(9)
End Select
'15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
' , , , ,
'ร้อย สิบ พัน ร้อย สิบ ตี้ ร้อย สิบ ล้าน แสน สิบ พัน ร้อย สิบ หน่วย
Select Case ColNum
Case Is = 1 'หน่วย
ColChar = Empty
Case Is = 2, 5, 8, 11, 14 'สิบ
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
ElseIf Mid(sNum, N, 1) = "2" Then
ColChar = ds(12) 'sao
Else
ColChar = ds(10) 'sip
End If
Case Is = 3, 9, 12, 15 'ร้อย
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = ds(13)
End If
Case Is = 4, 13 'พัน
If Mid(sNum, N, 1) = "0" Then
If Not Mid(sNum, Len(sNum) - ColNum, 1) > 0 Then
ColChar = Empty
Else
ColChar = ds(14)
End If
Else
ColChar = ds(14)
End If
Case Is = 6 'แสน
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = ds(15)
End If
Case Is = 7 'ล้าน
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = ds(16)
End If
If Len(sNum) > 7 And Len(sNum) < 11 Then ColChar = ds(16)
Case Is = 10 'ตี้
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = ds(17)
End If
If Len(sNum) > 11 Then ColChar = ds(17)
End Select
AllChar = NumChar & ColChar & AllChar
Next N
LaoNSound = AllChar
End Function
Function JpNSound(ByVal sNum, Optional oOption As String = "N")
'Japanese Number Sound 1.0 (Developed from Thai)
'by Pongsathorn Sraouthai
'for use with integer number only, if it was decimal, it will displaying as integer.
'oOption are following
'"N" = Normal (Default)
'"DB" = Daiji Bank Style (for 1, 2, 3, 5, 10, 100, and 1,000)
'"DA" = Daiji All digits
'0 = chrw(12295) zero
'1 = chrw(19968) ichi
'2 = chrw(20108) ni
'3 = chrw(19977) san
'4 = chrw(22235) shi
'5 = chrw(20116) go
'6 = chrw(20845) roku
'7 = chrw(19971) shichi
'8 = chrw(20843) hachi
'9 = chrw(20061) kyu
'10-10 = chrw(21313) ju
'11-100 = chrw(30334) hyaku
'12-1,000 = chrw(21315) sen
'13-10,000 = chrw(19975) man
'14-100,000,000 = chrw(20740) oku
'15-1,000,000,000,000 = chrw(20806) Sho
'16-10,000,000,000,000,000 = chrw(20140) Ke
'บาท = 12496 12540 12484
'สตางค์ = 12469 12479 12531
Dim AllChar As String
Dim NumChar As String
Dim ColChar As String
Dim ColNum As Long
Dim N
Dim nPos As Long
Dim nStr As String, nDec As String
Dim nds(0 To 16)
Select Case oOption
Case "N"
'General Number
nds(0) = U2W("12295")
nds(1) = U2W("19968")
nds(2) = U2W("20108")
nds(3) = U2W("19977")
nds(4) = U2W("22235")
nds(5) = U2W("20116")
nds(6) = U2W("20845")
nds(7) = U2W("19971")
nds(8) = U2W("20843")
nds(9) = U2W("20061")
nds(10) = U2W("21313")
nds(11) = U2W("30334")
nds(12) = U2W("21315")
nds(13) = U2W("19975")
nds(14) = U2W("20740")
nds(15) = U2W("20806")
nds(16) = U2W("20140")
Case "DB"
'Daiji for Bank for 1, 2, 3, 5, 10, 100, and 1,000
nds(0) = U2W("12295") '0
nds(1) = U2W("22769") '1
nds(2) = U2W("24336") '2
nds(3) = U2W("21442") '3
nds(4) = U2W("22235") '4
nds(5) = U2W("20116") '5
nds(6) = U2W("20845") '6
nds(7) = U2W("19971") '7
nds(8) = U2W("20843") '8
nds(9) = U2W("20061") '9
nds(10) = U2W("25342") '10
nds(11) = U2W("30334") '100
nds(12) = U2W("21315") '1000
nds(13) = U2W("-31700") '10000
nds(14) = U2W("20740") '100,000,000
nds(15) = U2W("20806") '1,000,000,000,000
nds(16) = U2W("20140") '10,000,000,000,000,000
Case "DA"
'Daiji for all numbers
nds(0) = U2W("12295") '0
nds(1) = U2W("22769") '1
nds(2) = U2W("24336") '2
nds(3) = U2W("21442") '3
nds(4) = U2W("22235") '4
nds(5) = U2W("20116") '5
nds(6) = U2W("20845") '6
nds(7) = U2W("19971") '7
nds(8) = U2W("20843") '8
nds(9) = U2W("20061") '9
nds(10) = U2W("25342") '10
nds(11) = U2W("30334") '100
nds(12) = U2W("21315") '1000
nds(13) = U2W("-31700") '10000
nds(14) = U2W("20740") '100,000,000
nds(15) = U2W("20806") '1,000,000,000,000
nds(16) = U2W("20140") '10,000,000,000,000,000
End Select
ColNum = 0
'Check if decimal number
nPos = InStr(1, sNum, ".", vbTextCompare)
If nPos >= 2 Then
nStr = Mid(sNum, 1, nPos - 1)
sNum = nStr
End If
For N = Len(sNum) To 1 Step -1
ColNum = ColNum + 1
Select Case Mid(sNum, N, 1)
Case Is = "0"
If ColNum < Len(sNum) Then
NumChar = Empty
Else
NumChar = nds(0)
End If
Case Is = "1"
If ColNum = 15 Or ColNum = 14 Or ColNum = 11 Or ColNum = 10 Or ColNum = 7 Or ColNum = 6 Or ColNum = 3 Or ColNum = 2 And Len(sNum) > ColNum Then
NumChar = Empty
ElseIf ColNum = 2 Or ColNum = 4 Or ColNum = 8 Or ColNum = 12 And Len(sNum) = ColNum Then
NumChar = Empty
Else
NumChar = nds(1)
End If
Case Is = "2"
NumChar = nds(2)
Case Is = "3"
NumChar = nds(3)
Case Is = "4"
NumChar = nds(4)
Case Is = "5"
NumChar = nds(5)
Case Is = "6"
NumChar = nds(6)
Case Is = "7"
NumChar = nds(7)
Case Is = "8"
NumChar = nds(8)
Case Is = "9"
NumChar = nds(9)
End Select
'case 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
' ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ หน่วย
' ร้อย สิบ โช พัน ร้อย สิบ โอกุ พัน ร้อย สิบ หมื่น พัน ร้อย สิบ หน่วย
Select Case ColNum
Case Is = 1
ColChar = Empty
Case Is = 2, 6, 10, 14
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = nds(10) 'สิบ
End If
Case Is = 3, 7, 11, 15
If Mid(sNum, N, 1) = "0" Then
If Not Mid(sNum, Len(sNum) - (ColNum - 1), 1) > 0 Then
ColChar = Empty
Else
ColChar = nds(11)
End If
Else
ColChar = nds(11) 'ร้อย
End If
Case Is = 4, 8, 12, 16
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = nds(12) 'พัน
End If
Case Is = 5
If Mid(sNum, N, 1) = "0" Then
'x0x,xxx
If Len(sNum) > ColNum And Mid(sNum, Len(sNum) - ColNum, 1) <> "0" Then
ColChar = nds(13)
'x,x0x,xxx
ElseIf Len(sNum) > ColNum And Mid(sNum, Len(sNum) - (ColNum + 1), 1) <> "0" Then
ColChar = nds(13)
Else
ColChar = Empty
End If
Else
ColChar = nds(13) 'หมื่น
End If
Case Is = 9
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = nds(14) 'หมื่นหมื่น
End If
Case Is = 13
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = nds(15) 'หมื่นหมื่นหมื่น
End If
Case Is = 17
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = nds(16) 'หมื่นหมื่นหมื่นหมื่น
End If
End Select
AllChar = NumChar & ColChar & AllChar
Next N
If val(sNum) = 0 Or sNum = "" Then
JpNSound = ChrW(12295)
Else
JpNSound = AllChar
End If
End Function
Function KoNSound(ByVal sNum, Optional oOption As String = "HGS")
'Korean Number Sound 1.0 (Developed from Thai)
'by Pongsathorn Sraouthai
'for use with integer number only, if it was decimal, it will displaying as integer.
'oOption are following
'"HGS" = Hangul Sino Cardinal (Default)
'"HJ" = Hanja Sino Cardinal
'บาท = -17388 -11592
'สตางค์ = -16212 -12092
Dim AllChar As String
Dim NumChar As String
Dim ColChar As String
Dim ColNum As Long
Dim N
Dim nPos As Long
Dim nStr As String, nDec As String
Dim nds(0 To 15)
Select Case oOption
Case "HGS"
'General Number
nds(0) = U2W("-14847") '0 yeong
nds(1) = U2W("-14468") '1 il
nds(2) = U2W("-14476") '2 i
nds(3) = U2W("-16196") '3 sam
nds(4) = U2W("-16212") '4 sa
nds(5) = U2W("-14812") '5 o
nds(6) = U2W("-14559") '6 yuk
nds(7) = U2W("-12704") '7 chil
nds(8) = U2W("-11500") '8 pal
nds(9) = U2W("-21140") '9 gu
nds(10) = U2W("-15635") '10 sip
nds(11) = U2W("-17359") '100 baek
nds(12) = U2W("-13156") '1000 cheon
nds(13) = U2W("-17972") '10000 man
nds(14) = U2W("-14923") '100,000,000 eok
nds(15) = U2W("-14224") '1,000,000,000,000 jo
Case "HJ"
'Daiji for Bank for 1, 2, 3, 5, 10, 100, and 1,000
nds(0) = U2W("-26890") '0 yeong
nds(1) = U2W("19968") '1 il
nds(2) = U2W("20108") '2 i
nds(3) = U2W("19977") '3 sam
nds(4) = U2W("22235") '4 sa
nds(5) = U2W("20116") '5 o
nds(6) = U2W("20845") '6 yuk
nds(7) = U2W("19971") '7 chil
nds(8) = U2W("20843") '8 pal
nds(9) = U2W("20061") '9 gu
nds(10) = U2W("21313") '10 sip
nds(11) = U2W("30334") '100 beak
nds(12) = U2W("21315") '1000 cheon
nds(13) = U2W("-31700") '10000 man
nds(14) = U2W("20740") '100,000,000 eok
nds(15) = U2W("20806") '1,000,000,000,000 jo
End Select
ColNum = 0
'Check if decimal number
nPos = InStr(1, sNum, ".", vbTextCompare)
If nPos >= 2 Then
nStr = Mid(sNum, 1, nPos - 1)
sNum = nStr
End If
For N = Len(sNum) To 1 Step -1
ColNum = ColNum + 1
Select Case Mid(sNum, N, 1)
Case Is = "0"
If ColNum < Len(sNum) Then
NumChar = Empty
Else
NumChar = nds(0)
End If
Case Is = "1"
If ColNum = 15 Or ColNum = 14 Or ColNum = 11 Or ColNum = 10 Or ColNum = 7 Or ColNum = 6 Or ColNum = 3 Or ColNum = 2 And Len(sNum) > ColNum Then
NumChar = Empty
ElseIf ColNum = 2 Or ColNum = 4 Or ColNum = 8 Or ColNum = 12 And Len(sNum) = ColNum Then
NumChar = Empty
Else
NumChar = nds(1)
End If
Case Is = "2"
NumChar = nds(2)
Case Is = "3"
NumChar = nds(3)
Case Is = "4"
NumChar = nds(4)
Case Is = "5"
NumChar = nds(5)
Case Is = "6"
NumChar = nds(6)
Case Is = "7"
NumChar = nds(7)
Case Is = "8"
NumChar = nds(8)
Case Is = "9"
NumChar = nds(9)
End Select
'case 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
' ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ หน่วย
' แบก สิบ โจ ชอน แบก สิบ โอก ชอน แบก สิบ หมั่น ชอน แบก สิบ หน่วย
'
Select Case ColNum
Case Is = 1
ColChar = Empty
Case Is = 2, 6, 10, 14
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = nds(10) 'สิบ
End If
Case Is = 3, 7, 11, 15
If Mid(sNum, N, 1) = "0" Then
If Not Mid(sNum, Len(sNum) - (ColNum - 1), 1) > 0 Then
ColChar = Empty
Else
ColChar = nds(11)
End If
Else
ColChar = nds(11) 'ร้อย
End If
Case Is = 4, 8, 12
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = nds(12) 'พัน
End If
Case Is = 5
If Mid(sNum, N, 1) = "0" Then
'x0x,xxx
If Len(sNum) > ColNum And Mid(sNum, Len(sNum) - ColNum, 1) <> "0" Then
ColChar = nds(13)
'x,x0x,xxx
ElseIf Len(sNum) > ColNum And Mid(sNum, Len(sNum) - (ColNum + 1), 1) <> "0" Then
ColChar = nds(13)
Else
ColChar = Empty
End If
Else
ColChar = nds(13) 'หมื่น
End If
Case Is = 9
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = nds(14) 'หมื่นหมื่น
End If
Case Is = 13
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = nds(15) 'หมื่นหมื่นหมื่น
End If
End Select
AllChar = NumChar & ColChar & AllChar
Next N
If val(sNum) = 0 Or sNum = "" Then
KoNSound = nds(0)
Else
KoNSound = AllChar
End If
End Function
Function CNSound(ByVal sNum)
'Chinese Number Sound 1.0 (Developed from Thai)
'by Pongsathorn Sraouthai
'for use with integer number only, if it was decimal, it will displaying as integer.
'0 = chrw(12295) ling
'1 = chrw(19968) yi
'2 = chrw(20108) er
'3 = chrw(19977) san
'4 = chrw(22235) si
'5 = chrw(20116) wu
'6 = chrw(20845) liu
'7 = chrw(19971) qi
'8 = chrw(20843) ba
'9 = chrw(20061) jiu
'10 = chrw(21313) shi
'100 = chrw(30334) yibai
'1,000 = chrw(21315) yiqian
'10,000 = chrw(19975) yiwan
'100,000,000 = chrw(20159) yi
'1,000,000,000,000= chrw(20806) zhao
'บาท = chrw(27888) & chrw(38114)
'สตางค์ = chrw(27801) & chrw(24403)
Dim AllChar As String
Dim NumChar As String
Dim ColChar As String
Dim ColNum As Long
Dim N
Dim nPos As Long
Dim nStr As String, nDec As String
ColNum = 0
'Check if decimal number
nPos = InStr(1, sNum, ".", vbTextCompare)
If nPos >= 2 Then
nStr = Mid(sNum, 1, nPos - 1)
sNum = nStr
End If
For N = Len(sNum) To 1 Step -1
ColNum = ColNum + 1
Select Case Mid(sNum, N, 1)
Case Is = "0"
If ColNum = 14 Or ColNum = 10 Or ColNum = 6 Or ColNum = 2 _
And Len(sNum) > ColNum And Right(sNum, 1) <> "0" Then
'X0XXX0XXX0XXX0X
Select Case Len(sNum)
Case 3
NumChar = ChrW(12295) '0
Case 7, 11, 15
If Mid(sNum, 3, 1) <> "0" Then
NumChar = ChrW(12295)
Else
NumChar = Empty
End If
Case Else
NumChar = Empty
End Select
ElseIf ColNum = 1 And sNum = "0" And Len(sNum) = 1 Then
NumChar = ChrW(12295)
Else
NumChar = Empty
End If
Case Is = "1"
'X1XXX1XXX1XXX1X
If ColNum = 14 Or ColNum = 10 Or ColNum = 6 Or ColNum = 2 Then
NumChar = Empty
Else
NumChar = ChrW(19968)
End If
Case Is = "2"
NumChar = ChrW(20108)
Case Is = "3"
NumChar = ChrW(19977)
Case Is = "4"
NumChar = ChrW(22235)
Case Is = "5"
NumChar = ChrW(20116)
Case Is = "6"
NumChar = ChrW(20845)
Case Is = "7"
NumChar = ChrW(19971)
Case Is = "8"
NumChar = ChrW(20843)
Case Is = "9"
NumChar = ChrW(20061)
End Select
'case 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
' ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ หน่วย
' ร้อย สิบ หมื่น พัน ร้อย สิบ ยี พัน ร้อย สิบ หมื่น พัน ร้อย สิบ หน่วย
Select Case ColNum
Case Is = 1
ColChar = Empty
Case Is = 2, 6, 10, 14
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = ChrW(21313) 'สิบ
End If
Case Is = 3, 7, 11, 15
If Mid(sNum, N, 1) = "0" Then
If Not Mid(sNum, Len(sNum) - (ColNum - 1), 1) > 0 Then
ColChar = Empty
Else
ColChar = ChrW(30334)
End If
Else
ColChar = ChrW(30334) 'ร้อย
End If
Case Is = 4, 8, 12
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = ChrW(21315) 'พัน
End If
Case Is = 5, 13
If Mid(sNum, N, 1) = "0" Then
'x0x,xxx
If Len(sNum) > ColNum And Mid(sNum, Len(sNum) - ColNum, 1) <> "0" Then
ColChar = ChrW(19975)
'x,x0x,xxx
ElseIf Len(sNum) > ColNum And Mid(sNum, Len(sNum) - (ColNum + 1), 1) <> "0" Then
ColChar = ChrW(19975)
Else
ColChar = Empty
End If
Else
ColChar = ChrW(19975) 'หมื่น
End If
Case Is = 9
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = ChrW(20159) 'หมื่นหมื่น ร้อยล้าน
End If
'Case Is = 13
' If Mid(sNum, n, 1) = "0" Then
' ColChar = Empty
' Else
' ColChar = ChrW(20806) 'หมื่นหมื่นหมื่น ล้านล้าน
' End If
End Select
AllChar = NumChar & ColChar & AllChar
Next N
If val(sNum) = 0 Or sNum = "" Then
CNSound = ChrW(12295)
Else
CNSound = AllChar
End If
End Function
Function MyNSound(ByVal sNum)
'Myanmar Number Sound 1.0 (Developed from Thai)
'by Pongsathorn Sraouthai
'for use with long number only, if it was decimal, it will displaying as integer.
Dim AllChar As String
Dim NumChar As String
Dim ColChar As String
Dim ColNum As Long
Dim N
Dim nPos As Long
Dim nStr As String, nDec As String
ColNum = 0
'Check if decimal number
nPos = InStr(1, sNum, ".", vbTextCompare)
If nPos >= 2 Then
nStr = Mid(sNum, 1, nPos - 1)
sNum = nStr
End If
If Len(sNum) > 15 Then Exit Function
For N = Len(sNum) To 1 Step -1
ColNum = ColNum + 1
Select Case Mid(sNum, N, 1)
Case Is = "0"
If val(sNum) = 0 Or sNum = "" Then
NumChar = U2W("4126 4143 4106") '"ศูนย์"
Else
NumChar = Empty
End If
Case Is = "1"
If ColNum = 2 Or ColNum = 9 Or ColNum = 15 Then
NumChar = Empty
Else
NumChar = U2W("4112 4101 4154") '"หนึ่ง"
End If
Case Is = "2"
NumChar = U2W("4116 4158 4101 4154") '"สอง"
Case Is = "3"
NumChar = U2W("4126 4143 4150 4152") '"สาม"
Case Is = "4"
NumChar = U2W("4124 4145 4152") '"สี่"
Case Is = "5"
NumChar = U2W("4100 4139 4152") '"ห้า"
Case Is = "6"
NumChar = U2W("4097 4156 4145 4140 4096 4154") '"หก"
Case Is = "7"
NumChar = U2W("4097 4143 4116 4101 4154") '"เจ็ด"
Case Is = "8"
NumChar = U2W("4123 4158 4101 4154") '"แปด"
Case Is = "9"
NumChar = U2W("4096 4141 4143 4152") '"เก้า"
End Select
'case 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1
' ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ หน่วย
Select Case ColNum
Case Is = 1
ColChar = Empty
Case Is = 2, 9, 15
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
ElseIf val(Right(sNum, 1)) = 0 Then
ColChar = U2W("4102 4122 4154")
Else
ColChar = U2W("4102 4122 4151 4154") '"สิบ"
End If
Case Is = 3, 10
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
ElseIf val(Right(sNum, 2)) = 0 Then
ColChar = U2W("4123 4140") '"ร้อย"
Else
ColChar = U2W("4123 4140 4151")
End If
Case Is = 4, 11
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
ElseIf val(Right(sNum, 3)) = 0 Then
ColChar = U2W("4113 4145 4140 4100 4154")
Else
ColChar = U2W("4113 4145 4140 4100 4151 4154") '"พัน"
End If
Case Is = 5, 12
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("4126 4145 4140 4100 4154 4152") '"หมื่น"
End If
Case Is = 6, 13
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("4126 4141 4116 4154 4152") '"แสน"
End If
Case Is = 7
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("4126 4116 4154 4152") '"ล้าน"
End If
Case Is = 8
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("4096 4143 4107 4145") '"สิบล้าน"
End If
Case Is = 14
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("4096 4145 4140 4107 4141") '"สิบล้านล้าน"
End If
'ถ้ามากกว่าหลักสูงสุด
If Len(sNum) > 8 Then ColChar = U2W("4096 4143 4107 4145") '"ล้าน"
End Select
AllChar = NumChar & ColChar & AllChar
Next N
MyNSound = AllChar
End Function
Private Function FirstNumber(inText) As Boolean
'For detect first number and following with zero
'use with Myanmar Number
If IsNumeric(Mid(inText, 1, 1)) Then
If val(Mid(inText, 2)) = 0 Then
FirstNumber = True
Else
FirstNumber = False
End If
Else
Exit Function
End If
End Function
Function KmNSound(ByVal sNum)
'Khmer Number Sound 1.0 (Developed from Thai)
'by Pongsathorn Sraouthai
'for use with integer number only, if it was decimal, it will displaying as integer.
Dim AllChar As String
Dim NumChar As String
Dim ColChar As String
Dim ColNum As Long
Dim N
Dim nPos As Long
Dim nStr As String, nDec As String
ColNum = 0
'Check if decimal number
nPos = InStr(1, sNum, ".", vbTextCompare)
If nPos >= 2 Then
nStr = Mid(sNum, 1, nPos - 1)
sNum = nStr
End If
If Len(sNum) > 15 Then Exit Function
For N = Len(sNum) To 1 Step -1
ColNum = ColNum + 1
Select Case Mid(sNum, N, 1)
Case Is = "0"
If val(sNum) = 0 Or sNum = "" Then
NumChar = U2W("6047 6076 6035 6098 6041") 'ศูนย์
Else
NumChar = Empty
End If
Case Is = "1"
If ColNum = 14 And Len(sNum) >= 14 Or ColNum = 8 And Len(sNum) >= 8 Or ColNum = 2 And Len(sNum) >= 2 Then
NumChar = Empty
Else
NumChar = U2W("6040 6077 6041") '"หนึ่ง"
End If
Case Is = "2"
If ColNum = 14 And Len(sNum) >= 14 Or ColNum = 8 And Len(sNum) >= 8 Or ColNum = 2 And Len(sNum) >= 2 Then
NumChar = Empty
Else
NumChar = U2W("6038 6072 6042") '"สอง"
End If
Case Is = "3"
If ColNum = 14 And Len(sNum) >= 14 Or ColNum = 8 And Len(sNum) >= 8 Or ColNum = 2 And Len(sNum) >= 2 Then
NumChar = Empty
Else
NumChar = U2W("6036 6072") '"สาม"
End If
Case Is = "4"
If ColNum = 14 And Len(sNum) >= 14 Or ColNum = 8 And Len(sNum) >= 8 Or ColNum = 2 And Len(sNum) >= 2 Then
NumChar = Empty
Else
NumChar = U2W("6036 6077 6035") '"สี่"
End If
Case Is = "5"
If ColNum = 14 And Len(sNum) >= 14 Or ColNum = 8 And Len(sNum) >= 8 Or ColNum = 2 And Len(sNum) >= 2 Then
NumChar = Empty
Else
NumChar = U2W("6036 6098 6042 6070 6086") 'ห้า
End If
Case Is = "6"
If ColNum = 14 And Len(sNum) >= 14 Or ColNum = 8 And Len(sNum) >= 8 Or ColNum = 2 And Len(sNum) >= 2 Then
NumChar = Empty
Else
NumChar = U2W("6036 6098 6042 6070 6086 6040 6077 6041") '"หก"
End If
Case Is = "7"
If ColNum = 14 And Len(sNum) >= 14 Or ColNum = 8 And Len(sNum) >= 8 Or ColNum = 2 And Len(sNum) >= 2 Then
NumChar = Empty
Else
NumChar = U2W("6036 6098 6042 6070 6086 6038 6072 6042") '"เจ็ด"
End If
Case Is = "8"
If ColNum = 14 And Len(sNum) >= 14 Or ColNum = 8 And Len(sNum) >= 8 Or ColNum = 2 And Len(sNum) >= 2 Then
NumChar = Empty
Else
NumChar = U2W("6036 6098 6042 6070 6086 6036 6072") '"แปด"
End If
Case Is = "9"
If ColNum = 14 And Len(sNum) >= 14 Or ColNum = 8 And Len(sNum) >= 8 Or ColNum = 2 And Len(sNum) >= 2 Then
NumChar = Empty
Else
NumChar = U2W("6036 6098 6042 6070 6086 6036 6077 6035") '"เก้า"
End If
End Select
'case 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1
' ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ หน่วย
Select Case ColNum
Case Is = 1
ColChar = Empty
Case Is = 2, 8, 14
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
Select Case Mid(sNum, N, 1) 'กรณีหลักสิบต่างจากหลักหน่วย
Case 1
ColChar = U2W("6026 6036 6091") '"สิบ"
Case 2
ColChar = U2W("6040 6098 6039 6083") '20
Case 3
ColChar = U2W("6047 6070 6040 6047 6071 6036") '30
Case 4
ColChar = U2W("6047 6082 6047 6071 6036")
Case 5
ColChar = U2W("6048 6070 6047 6071 6036")
Case 6
ColChar = U2W("6048 6075 6016 6047 6071 6036")
Case 7
ColChar = U2W("6021 6071 6031 6047 6071 6036")
Case 8
ColChar = U2W("6036 6089 6082 6031 6047 6071 6036")
Case 9
ColChar = U2W("6016 6085 6047 6071 6036")
End Select
End If
Case Is = 3, 9, 15
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("6042 6041") '"ร้อย"
End If
Case Is = 4, 10
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("6038 6070 6035 6091") '"พัน"
End If
Case Is = 5, 11
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("6040 6089 6074 6035") '"หมื่น"
End If
Case Is = 6, 12
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("6047 6082 6035") '"แสน"
End If
Case Is = 7, 13
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("6043 6070 6035") '"ล้าน"
End If
If Len(sNum) > 7 Then ColChar = U2W("6043 6070 6035") '"ล้าน"
End Select
AllChar = NumChar & ColChar & AllChar
Next N
KmNSound = AllChar
End Function
Function KM2W(strInput As String) As String
'Convert Khmer numeral to Western numeral
Dim numberArray
numberArray = Array(ChrW(6112), "0", _
ChrW(6113), "1", _
ChrW(6114), "2", _
ChrW(6115), "3", _
ChrW(6116), "4", _
ChrW(6117), "5", _
ChrW(6118), "6", _
ChrW(6119), "7", _
ChrW(6120), "8", _
ChrW(6121), "9")
Dim i As Long
KM2W = strInput
For i = 0 To 18 Step 2
KM2W = Replace(KM2W, numberArray(i), numberArray(i + 1))
Next i
End Function
Function W2KM(strInput As String) As String
'Convert Western numeral to Khmer numeral
Dim numberArray
numberArray = Array("0", ChrW(6112), _
"1", ChrW(6113), _
"2", ChrW(6114), _
"3", ChrW(6115), _
"4", ChrW(6116), _
"5", ChrW(6117), _
"6", ChrW(6118), _
"7", ChrW(6119), _
"8", ChrW(6120), _
"9", ChrW(6121))
Dim i As Long
W2KM = strInput
For i = 0 To 18 Step 2
W2KM = Replace(W2KM, numberArray(i), numberArray(i + 1))
Next i
End Function
Function VnNSound(ByVal sNum)
'Vietnamese Number Sound 1.0 (Developed from Thai)
'by Pongsathorn Sraouthai
'for use with integer number only, if it was decimal, it will displaying as integer.
Dim AllChar As String
Dim NumChar As String
Dim ColChar As String
Dim ColNum As Long
Dim N
Dim nPos As Long
Dim nStr As String, nDec As String
ColNum = 0
'Check if decimal number
nPos = InStr(1, sNum, ".", vbTextCompare)
If nPos > 0 Then
nStr = Mid(sNum, 1, nPos - 1)
sNum = nStr
End If
If Len(sNum) > 15 Then Exit Function
For N = Len(sNum) To 1 Step -1
ColNum = ColNum + 1
Select Case Mid(sNum, N, 1)
Case Is = "0"
If val(sNum) = 0 Or sNum = "" Then
NumChar = U2W("75 104 244 110 103 32") 'ศูนย์
ElseIf ColNum = 2 Or ColNum = 5 Or ColNum = 8 Or ColNum = 11 Or ColNum = 14 Then
If Len(sNum) > ColNum And val(Left(Right(sNum, ColNum - 1), 1)) <> 0 Then
NumChar = U2W("76 7867 32")
Else
NumChar = Empty
End If
ElseIf ColNum = 3 Or ColNum = 6 Or ColNum = 9 Or ColNum = 12 Then
If Len(sNum) > ColNum And val(Left(Right(sNum, ColNum - 1), 2)) <> 0 Then
NumChar = U2W("75 104 244 110 103 32")
Else
NumChar = Empty
End If
Else
NumChar = Empty
End If
Case Is = "1"
If ColNum = 2 Or ColNum = 5 Or ColNum = 8 Or ColNum = 11 Or ColNum = 14 Then
If Len(sNum) >= ColNum Then NumChar = Empty
ElseIf ColNum = 1 Or ColNum = 4 Or ColNum = 7 Or ColNum = 10 Or ColNum = 13 Then
If Len(sNum) > ColNum And val(Left(Right(sNum, (Len(sNum) - ColNum) + 1), 2)) > 20 Then
NumChar = U2W("77 7889 116 32")
Else
NumChar = U2W("77 7897 116 32")
End If
Else
NumChar = U2W("77 7897 116 32") '"หนึ่ง"
End If
Case Is = "2"
NumChar = U2W("72 97 105 32") '"สอง" '2.5
Case Is = "3"
NumChar = U2W("66 97 32") '"สาม"
Case Is = "4"
If ColNum = 1 Or ColNum = 4 Or ColNum = 7 Or ColNum = 10 Or ColNum = 13 Then
If Len(sNum) > ColNum And val(Left(Right(sNum, (Len(sNum) - ColNum) + 1), 2)) > 20 Then
NumChar = U2W("84 432 32")
Else
NumChar = U2W("66 7889 110 32")
End If
Else
NumChar = U2W("66 7889 110 32") '"สี่" 12345678
End If
Case Is = "5"
If ColNum = 1 Or ColNum = 4 Or ColNum = 7 Or ColNum = 10 Or ColNum = 13 Then
If Len(sNum) > ColNum And val(Left(Right(sNum, (Len(sNum) - ColNum) + 1), 2)) > 10 Then
NumChar = U2W("76 259 109 32")
Else
NumChar = U2W("78 259 109 32")
End If
Else
NumChar = U2W("78 259 109 32") '"ห้า"
End If
Case Is = "6"
NumChar = U2W("83 225 117 32") '"หก"
Case Is = "7"
NumChar = U2W("66 7843 121 32") '"เจ็ด"
Case Is = "8"
NumChar = U2W("84 225 109 32") '"แปด"
Case Is = "9"
NumChar = U2W("67 104 237 110 32") '"เก้า"
End Select
'case 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1
' ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ ล้าน แสน หมื่น พัน ร้อย สิบ หน่วย
Select Case ColNum
Case Is = 1
ColChar = Empty
Case Is = 2, 5, 8, 11, 14
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
ElseIf val(Left(Right(sNum, ColNum), 2)) >= 20 Then
ColChar = U2W("77 432 417 105 32")
Else
ColChar = U2W("77 432 7901 105 32") '"สิบ"
End If
Case Is = 3, 6, 9, 12, 15
If Mid(sNum, N, 1) <> "0" Then
ColChar = U2W("84 114 259 109 32") '"ร้อย"
ElseIf val(Left(Right(sNum, ColNum), 2)) > 0 Then
ColChar = U2W("84 114 259 109 32")
ElseIf val(Left(Right(sNum, ColNum + 1), 2)) > 0 Then
ColChar = U2W("84 114 259 109 32")
Else
ColChar = Empty '"ร้อย"
End If
Case Is = 4, 13
If Mid(sNum, N, 1) = "0" And Len(sNum) >= 7 Then
ColChar = Empty
Else
ColChar = U2W("78 103 104 236 110 32") '"พัน"
End If
Case Is = 7
If Mid(sNum, N, 1) = "0" And Len(sNum) >= 10 Then
ColChar = Empty
Else
ColChar = U2W("84 114 105 7879 117 32") 'ล้าน
End If
Case Is = 10
If Mid(sNum, N, 1) = "0" Then
ColChar = Empty
Else
ColChar = U2W("84 7927 32") 'พันล้าน
End If
If Len(sNum) > 10 Then ColChar = U2W("84 7927 32") '"พันล้าน"
If Len(sNum) > 13 Then ColChar = U2W("78 103 104 236 110 32 84 7927 32")
End Select
AllChar = NumChar & ColChar & AllChar
Next N
VnNSound = Trim(AllChar)
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment