กระทู้เก่าบอร์ด อ.Yeadram
1,526 0
URL.หัวข้อ /
URL
มีฟังชั่น BathText มาฝากครับ :)
ไปเจอมา สามารถใช้งานได้ดี เลยนำมาฝากพี่ๆเพื่อนๆครับ เผื่อจะเป็นประโยชน์ไม่มากก็น้อย :D
การใช้งานก็แบบนี้ครับเวลาพิมพ์ใน textbox
="("+Convert_Num([ชื่อtextbox])+")"
credit : http://www.thaiadmin.org/board/index.phpaction=printpage;topic=83791.0
***(เพิ่มฟังชันนี้ในโมดูลก่อนนะครับ)
Function Convert_Num(Xvar)
Dim Thai_number As String
ReDim n(1 To 9) As String
ReDim l(1 To 6) As String
Dim ed As String
Dim yee As String
Dim Baht As String
Dim Stang As String
Dim Nodecimal As String
Dim ntostr As String
Dim ndec As String
n(1) = "หนึ่ง"
n(2) = "สอง"
n(3) = "สาม"
n(4) = "สี"
n(5) = "ห้า"
n(6) = "หก"
n(7) = "เจ็ด"
n(8) = "แปด"
n(9) = "เก้า"
l(1) = "สิบ"
l(2) = "ร้อย"
l(3) = "พัน"
l(4) = "หมื่น"
l(5) = "แสน"
l(6) = "ล้าน"
ed = "เอ็ด"
yee = "ยี่"
Baht = "บาท"
Stang = "สตางค์"
Nodecimal = "ถ้วน"
Zero = "ศูนย์"
Dim Stt As Integer
Dim LSTR As Integer
Dim Decp As String
Dim nstr As String
Dim dcstr As String
Dim chknum As Integer
If Xvar <> 0 Then
ntostr = Xvar
nstr = Trim$(ntostr)
LSTR = Len(nstr)
Rem Decp = Mid$(ntostr, Lstr - 2, 1)
Rem ndec = Mid$(ntostr, Lstr - 1, 2)
Decp = " "
For I = 1 To Len(nstr)
If Mid$(nstr, I, 1) = "." Then
Decp = "."
Exit For
End If
Next I
If Decp = "." Then
If Len(nstr) < I + 2 Then
ndec = Mid$(nstr, I + 1, 1) + "0"
Else
ndec = Mid$(nstr, I + 1, 2)
End If
If Decp = "." Then
nstr = Mid$(nstr, 1, I - 1)
End If
End If
Dim schar As String
LSTR = I - 1
For b = 0 To LSTR - 1
schar = Mid$(nstr, LSTR - b, 1)
Select Case b
Case 0
If nstr = "1" Then
Thai_number = n(1)
Else
If schar = "1" Then
Thai_number = ed
Else
chknum = Val(schar)
If chknum > 0 Then
Thai_number = n(chknum)
End If
End If
End If
Case 1
If schar <> "0" Then
If schar = "1" Then
Thai_number = l(1) + Thai_number
Else
If schar = "2" Then
Thai_number = yee + l(1) + Thai_number
Else
chknum = Val(schar)
Thai_number = n(chknum) + l(1) + Thai_number
End If
End If
End If
Case Else
If schar <> "0" And schar <> "." Then
chknum = Val(schar)
Thai_number = n(chknum) + l(b) + Thai_number
End If
End Select
Next b
If Decp <> "." Or Val(ndec) = 0 Then
Thai_number = Thai_number + Baht + Nodecimal
Else
Thai_number = Thai_number + Baht
Select Case Val(ndec)
Case 0
Rem Thai_number = Thai_number + Baht
Case Is < 10
If Val(ndec) = 1 Then
Thai_number = Thai_number + ed
Else
Thai_number = Thai_number + n(Val(ndec))
End If
Case 10
Thai_number = Thai_number + l(1)
Case 11
Thai_number = Thai_number + l(1) + ed
Case 12 To 19
Thai_number = Thai_number + l(1) + n(Val(ndec) - 10)
Case 20
Thai_number = Thai_number + yee + l(1)
Case 21 To 29
If Val(ndec) = 21 Then
Thai_number = Thai_number + yee + l(1) + ed
Else
Thai_number = Thai_number + yee + l(1) + n(Val(ndec) - 20)
End If
Case Else
If Mid$(ndec, 2, 1) <> "0" Then
Thai_number = Thai_number + n(Val(Mid$(ndec, 1, 1))) + l(1) + n(Val(Mid$(ndec, 2, 1)))
Else
Thai_number = Thai_number + n(Val(Mid$(ndec, 1, 1))) + l(1)
End If
End Select
Thai_number = Thai_number + Stang
End If
Convert_Num = Thai_number
ElseIf Xvar = 0 Then
Convert_Num = Zero & Baht & Nodecimal
End If
End Function
การใช้งานก็แบบนี้ครับเวลาพิมพ์ใน textbox
="("+Convert_Num([ชื่อtextbox])+")"
credit : http://www.thaiadmin.org/board/index.phpaction=printpage;topic=83791.0
***(เพิ่มฟังชันนี้ในโมดูลก่อนนะครับ)
Function Convert_Num(Xvar)
Dim Thai_number As String
ReDim n(1 To 9) As String
ReDim l(1 To 6) As String
Dim ed As String
Dim yee As String
Dim Baht As String
Dim Stang As String
Dim Nodecimal As String
Dim ntostr As String
Dim ndec As String
n(1) = "หนึ่ง"
n(2) = "สอง"
n(3) = "สาม"
n(4) = "สี"
n(5) = "ห้า"
n(6) = "หก"
n(7) = "เจ็ด"
n(8) = "แปด"
n(9) = "เก้า"
l(1) = "สิบ"
l(2) = "ร้อย"
l(3) = "พัน"
l(4) = "หมื่น"
l(5) = "แสน"
l(6) = "ล้าน"
ed = "เอ็ด"
yee = "ยี่"
Baht = "บาท"
Stang = "สตางค์"
Nodecimal = "ถ้วน"
Zero = "ศูนย์"
Dim Stt As Integer
Dim LSTR As Integer
Dim Decp As String
Dim nstr As String
Dim dcstr As String
Dim chknum As Integer
If Xvar <> 0 Then
ntostr = Xvar
nstr = Trim$(ntostr)
LSTR = Len(nstr)
Rem Decp = Mid$(ntostr, Lstr - 2, 1)
Rem ndec = Mid$(ntostr, Lstr - 1, 2)
Decp = " "
For I = 1 To Len(nstr)
If Mid$(nstr, I, 1) = "." Then
Decp = "."
Exit For
End If
Next I
If Decp = "." Then
If Len(nstr) < I + 2 Then
ndec = Mid$(nstr, I + 1, 1) + "0"
Else
ndec = Mid$(nstr, I + 1, 2)
End If
If Decp = "." Then
nstr = Mid$(nstr, 1, I - 1)
End If
End If
Dim schar As String
LSTR = I - 1
For b = 0 To LSTR - 1
schar = Mid$(nstr, LSTR - b, 1)
Select Case b
Case 0
If nstr = "1" Then
Thai_number = n(1)
Else
If schar = "1" Then
Thai_number = ed
Else
chknum = Val(schar)
If chknum > 0 Then
Thai_number = n(chknum)
End If
End If
End If
Case 1
If schar <> "0" Then
If schar = "1" Then
Thai_number = l(1) + Thai_number
Else
If schar = "2" Then
Thai_number = yee + l(1) + Thai_number
Else
chknum = Val(schar)
Thai_number = n(chknum) + l(1) + Thai_number
End If
End If
End If
Case Else
If schar <> "0" And schar <> "." Then
chknum = Val(schar)
Thai_number = n(chknum) + l(b) + Thai_number
End If
End Select
Next b
If Decp <> "." Or Val(ndec) = 0 Then
Thai_number = Thai_number + Baht + Nodecimal
Else
Thai_number = Thai_number + Baht
Select Case Val(ndec)
Case 0
Rem Thai_number = Thai_number + Baht
Case Is < 10
If Val(ndec) = 1 Then
Thai_number = Thai_number + ed
Else
Thai_number = Thai_number + n(Val(ndec))
End If
Case 10
Thai_number = Thai_number + l(1)
Case 11
Thai_number = Thai_number + l(1) + ed
Case 12 To 19
Thai_number = Thai_number + l(1) + n(Val(ndec) - 10)
Case 20
Thai_number = Thai_number + yee + l(1)
Case 21 To 29
If Val(ndec) = 21 Then
Thai_number = Thai_number + yee + l(1) + ed
Else
Thai_number = Thai_number + yee + l(1) + n(Val(ndec) - 20)
End If
Case Else
If Mid$(ndec, 2, 1) <> "0" Then
Thai_number = Thai_number + n(Val(Mid$(ndec, 1, 1))) + l(1) + n(Val(Mid$(ndec, 2, 1)))
Else
Thai_number = Thai_number + n(Val(Mid$(ndec, 1, 1))) + l(1)
End If
End Select
Thai_number = Thai_number + Stang
End If
Convert_Num = Thai_number
ElseIf Xvar = 0 Then
Convert_Num = Zero & Baht & Nodecimal
End If
End Function
Time: 0.1133s