7
« เมื่อ: 01 เม.ย. 65 , 18:56:18 »
Function DoBathString(Num As String)
'ต้องขอขอบคุณผู้ที่เขียนโปรแกรมนี้เผยแพร่ในการตอบคำถามใน Pantip.com
Dim numstring(10) As String
Dim million As Integer
Dim hundred_million As Integer
Dim ten_thousand As Integer
Dim thousand As Integer
Dim hundred As Integer
Dim ten As Integer
Dim onebath As Integer
Dim inputstring As String
Dim numLen As Integer
Dim a As String
Dim result As String
Dim bTen As Boolean
numstring(1) = "ศูนย์"
numstring(2) = "หนึ่ง"
numstring(3) = "สอง"
numstring(4) = "สาม"
numstring(5) = "สี่"
numstring(6) = "ห้า"
numstring(7) = "หก"
numstring(8) = "เจ็ด"
numstring(9) = "แปด"
numstring(10) = "เก้า"
inputstring = Format$(Num, "######0.00")
numLen = Len(inputstring)
If numLen >= 10 Then
a = Left$(inputstring, numLen - 9)
If Len(a) = 1 Then result = numstring(Val(a) + 1) + "ล้าน"
End If
If numLen >= 9 Then
a = Mid$(inputstring, numLen - 8, 1)
result = result + numstring(Val(a) + 1) + "แสน"
End If
If numLen >= 8 Then
a = Mid$(inputstring, numLen - 7, 1)
If Val(a) > 0 Then result = result + numstring(Val(a) + 1) + "หมื่น"
End If
If numLen >= 7 Then
a = Mid$(inputstring, numLen - 6, 1)
If Val(a) > 0 Then result = result + numstring(Val(a) + 1) + "พัน"
End If
If numLen >= 6 Then
a = Mid$(inputstring, numLen - 5, 1)
If Val(a) > 0 Then result = result + numstring(Val(a) + 1) + "ร้อย"
End If
If numLen >= 5 Then
bTen = True
a = Mid$(inputstring, numLen - 4, 1)
If Val(a) = 0 Then bTen = False
If Val(a) = 1 Then result = result + "สิบ"
If Val(a) = 2 Then result = result + "ยี่สิบ"
If Val(a) >= 3 Then result = result + numstring(Val(a) + 1) + "สิบ"
End If
If numLen >= 4 Then
a = Mid$(inputstring, numLen - 3, 1)
If Val(a) = 0 And Len(result) = 0 And Right$(inputstring, 2) = "00" Then result = "ศูนย์"
If Val(a) = 1 Then
If bTen = True Then result = result + "เอ็ด"
If bTen = False Then result = result + "หนึ่ง"
End If
If Val(a) >= 2 Then result = result + numstring(Val(a) + 1)
End If
a = Right$(inputstring, 2)
If a = "00" Then
result = result + "บาทถ้วน"
Else
bTen = True
If Len(result) > 0 Then result = result + "บาท"
If Val(Left$(a, 1)) = 0 Then bTen = False
If Val(Left$(a, 1)) = 1 Then result = result + "สิบ"
If Val(Left$(a, 1)) = 2 Then result = result + "ยี่สิบ"
If Val(Left$(a, 1)) >= 3 Then result = result + numstring(Val(Left$(a, 1)) + 1) + "สิบ"
If Val(Right$(a, 1)) = 1 Then
If bTen = True Then result = result + "เอ็ด"
If bTen = False Then result = result + "หนึ่ง"
End If
If Val(Right$(a, 1)) >= 2 Then result = result + numstring(Val(Right$(a, 1)) + 1)
result = result + "สตางค์"
End If
DoBathString = result
End Function