Function changenum(num As String) As String
Dim i As Integer, max As Integer, r As String, n As String
num = Trim(Str(Val(num)))
max = Len(num)
For i = 1 To max
r = Choose(((max - i + 1) Mod 6) + 1, "แสน", "", "สิบ", "ร้อย", "พัน", "หมื่น")
n = Choose(Mid(num, i, 1) + 1, "ศูนย์", "หนึ่ง", "สอง", "สาม", "สี่", "ห้า", "หก", "เจ็ด", "แปด", "เก้า")
If r = "สิบ" And n = "หนึ่ง" Then n = ""
If n = "หนึ่ง" And r = "" And max <> 1 Then n = "เอ็ด"
If i = 1 And n = "เอ็ด" And max > 1 Then n = "หนึ่ง"
If r = "สิบ" And n = "สอง" Then n = "ยี่"
If r = "" And max - i + 1 > 6 Then r = "ล้าน"
If n <> "ศูนย์" Then
changenum = changenum & n & r
Else
If r = "ล้าน" Then changenum = changenum & r
End If
Next
End Function