Page 2 of 2

Re: สูครแปงตัวเลขเป็นคำ

Posted: Tue Jan 05, 2021 9:09 pm
by snasui
:D ลองนำ Code นี้ไปปรับดูครับ

Code: Select all

Option Explicit

'Main Function
Function SpellNumber(ByVal MyNumber)
    Dim Bahts, Stangs, Temp1, Temp2
    Dim DecimalPlace, Count, t As Variant
    ReDim Place(9) As String
    Place(2) = " Lan "
    Place(3) = " Lan "
    Place(4) = " Lan "
    Place(5) = " Lan "
    ' String representation of amount.
    MyNumber = Trim(Str(MyNumber))
    ' Position of decimal place 0 if none.
    DecimalPlace = InStr(MyNumber, ".")
    ' Convert Stangs and set MyNumber to Baht amount.
    If DecimalPlace > 0 Then
        Stangs = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    Count = 1
    Do While MyNumber <> ""
        Temp1 = GetHundreds(Right(MyNumber, 3))
        If Len(MyNumber) > 3 Then
            Temp2 = GetHundreds1(Right(Left(MyNumber, Len(MyNumber) - 3), 3))
        Else
            Temp2 = ""
        End If
        If Temp1 <> "" Then Bahts = Temp1 & Place(Count) & Bahts
        If Temp2 <> "" Then Bahts = Temp2 & Bahts
        If Len(MyNumber) > 6 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 6)
        Else
            MyNumber = ""
        End If
        Count = Count + 1
    Loop
    Select Case Bahts
    Case ""
        Bahts = "Soon"
    Case "Nueng"
        Bahts = "Nueng"
    Case Else
        If Right(Bahts, 6) = " Nueng" Then
            t = Split(Application.Trim(Bahts), " ")
            If InStr(t(UBound(t) - 1), "sib") Or InStr(t(UBound(t) - 1), "Xao") Then
                Bahts = Left(Bahts, Len(Bahts) - 6) & " Ed"
            Else
                Bahts = Left(Bahts, Len(Bahts) - 6) & " Nueng"
            End If
        Else
            Bahts = Bahts
        End If
    End Select
        
    Select Case Stangs
        Case ""
            Stangs = ""
        Case "Nueng"
            Stangs = " Nueng"
        Case Else
            Stangs = " " & Stangs & " Stangs"
    End Select
    SpellNumber = Bahts & Stangs
End Function

' Converts a number from 100-999 into text
Function GetHundreds1(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    ' Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & " San "
    End If
    ' Convert the tens and ones place.
'    If Mid(MyNumber, 2, 1) <> "0" Then
'        Result = Result & GetDigit(Mid(MyNumber, 2, 1)) & " Muen "
'    End If
    If Mid(MyNumber, 2, 2) <> "00" Then
        Result = Result & GetTens(Mid(MyNumber, 2, 2)) & " Pan "
    End If
    GetHundreds1 = Result
End Function
' Converts a number from 100-999 into text
Function GetHundreds(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    ' Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & " Roi "
    End If
    ' Convert the tens and ones place.
    If Mid(MyNumber, 2, 1) <> "0" Then
        Result = Result & GetTens(Mid(MyNumber, 2))
    Else
        Result = Result & GetDigit(Mid(MyNumber, 3))
    End If
    GetHundreds = Result
End Function

' Converts a number from 10 to 99 into text.
Function GetTens(TensText)
    Dim Result As String
    Result = "" ' Null out the temporary function value.
    If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
        Select Case Val(TensText)
            Case 10: Result = "Sib"
            Case 11: Result = "Sib-ed"
            Case 12: Result = "Sibsong"
            Case 13: Result = "Sibsam"
            Case 14: Result = "Sibsee"
            Case 15: Result = "Sibha"
            Case 16: Result = "Sibhok"
            Case 17: Result = "Sibjed"
            Case 18: Result = "Sibpad"
            Case 19: Result = "Sibkao"
            Case Else
        End Select
    Else ' If value between 20-99...
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "Xao "
            Case 3: Result = "Samsib "
            Case 4: Result = "Seesib "
            Case 5: Result = "Hasib "
            Case 6: Result = "Hoksib "
            Case 7: Result = "Jedsib "
            Case 8: Result = "Padsib "
            Case 9: Result = "Kaosib "
            Case Else
        End Select
        Result = Result & GetDigit(Right(TensText, 1))  ' Retrieve ones place.
    End If
    GetTens = Result
End Function

' Converts a number from 1 to 9 into text.
Function GetDigit(Digit)
    Select Case Val(Digit)
        Case 1: GetDigit = "Nueng"
        Case 2: GetDigit = "Song"
        Case 3: GetDigit = "Sam"
        Case 4: GetDigit = "See"
        Case 5: GetDigit = "Ha"
        Case 6: GetDigit = "Hok"
        Case 7: GetDigit = "Jed"
        Case 8: GetDigit = "Pad"
        Case 9: GetDigit = "Kao"
        Case Else: GetDigit = ""
    End Select
End Function

Re: สูครแปงตัวเลขเป็นคำ

Posted: Wed Jan 06, 2021 7:05 am
by วังวู ช่ง
snasui wrote: Tue Jan 05, 2021 9:09 pm :D ลองนำ Code นี้ไปปรับดูครับ

Code: Select all

Option Explicit

'Main Function
Function SpellNumber(ByVal MyNumber)
    Dim Bahts, Stangs, Temp1, Temp2
    Dim DecimalPlace, Count, t As Variant
    ReDim Place(9) As String
    Place(2) = " Lan "
    Place(3) = " Lan "
    Place(4) = " Lan "
    Place(5) = " Lan "
    ' String representation of amount.
    MyNumber = Trim(Str(MyNumber))
    ' Position of decimal place 0 if none.
    DecimalPlace = InStr(MyNumber, ".")
    ' Convert Stangs and set MyNumber to Baht amount.
    If DecimalPlace > 0 Then
        Stangs = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    Count = 1
    Do While MyNumber <> ""
        Temp1 = GetHundreds(Right(MyNumber, 3))
        If Len(MyNumber) > 3 Then
            Temp2 = GetHundreds1(Right(Left(MyNumber, Len(MyNumber) - 3), 3))
        Else
            Temp2 = ""
        End If
        If Temp1 <> "" Then Bahts = Temp1 & Place(Count) & Bahts
        If Temp2 <> "" Then Bahts = Temp2 & Bahts
        If Len(MyNumber) > 6 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 6)
        Else
            MyNumber = ""
        End If
        Count = Count + 1
    Loop
    Select Case Bahts
    Case ""
        Bahts = "Soon"
    Case "Nueng"
        Bahts = "Nueng"
    Case Else
        If Right(Bahts, 6) = " Nueng" Then
            t = Split(Application.Trim(Bahts), " ")
            If InStr(t(UBound(t) - 1), "sib") Or InStr(t(UBound(t) - 1), "Xao") Then
                Bahts = Left(Bahts, Len(Bahts) - 6) & " Ed"
            Else
                Bahts = Left(Bahts, Len(Bahts) - 6) & " Nueng"
            End If
        Else
            Bahts = Bahts
        End If
    End Select
        
    Select Case Stangs
        Case ""
            Stangs = ""
        Case "Nueng"
            Stangs = " Nueng"
        Case Else
            Stangs = " " & Stangs & " Stangs"
    End Select
    SpellNumber = Bahts & Stangs
End Function

' Converts a number from 100-999 into text
Function GetHundreds1(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    ' Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & " San "
    End If
    ' Convert the tens and ones place.
'    If Mid(MyNumber, 2, 1) <> "0" Then
'        Result = Result & GetDigit(Mid(MyNumber, 2, 1)) & " Muen "
'    End If
    If Mid(MyNumber, 2, 2) <> "00" Then
        Result = Result & GetTens(Mid(MyNumber, 2, 2)) & " Pan "
    End If
    GetHundreds1 = Result
End Function
' Converts a number from 100-999 into text
Function GetHundreds(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    ' Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & " Roi "
    End If
    ' Convert the tens and ones place.
    If Mid(MyNumber, 2, 1) <> "0" Then
        Result = Result & GetTens(Mid(MyNumber, 2))
    Else
        Result = Result & GetDigit(Mid(MyNumber, 3))
    End If
    GetHundreds = Result
End Function

' Converts a number from 10 to 99 into text.
Function GetTens(TensText)
    Dim Result As String
    Result = "" ' Null out the temporary function value.
    If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
        Select Case Val(TensText)
            Case 10: Result = "Sib"
            Case 11: Result = "Sib-ed"
            Case 12: Result = "Sibsong"
            Case 13: Result = "Sibsam"
            Case 14: Result = "Sibsee"
            Case 15: Result = "Sibha"
            Case 16: Result = "Sibhok"
            Case 17: Result = "Sibjed"
            Case 18: Result = "Sibpad"
            Case 19: Result = "Sibkao"
            Case Else
        End Select
    Else ' If value between 20-99...
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "Xao "
            Case 3: Result = "Samsib "
            Case 4: Result = "Seesib "
            Case 5: Result = "Hasib "
            Case 6: Result = "Hoksib "
            Case 7: Result = "Jedsib "
            Case 8: Result = "Padsib "
            Case 9: Result = "Kaosib "
            Case Else
        End Select
        Result = Result & GetDigit(Right(TensText, 1))  ' Retrieve ones place.
    End If
    GetTens = Result
End Function

' Converts a number from 1 to 9 into text.
Function GetDigit(Digit)
    Select Case Val(Digit)
        Case 1: GetDigit = "Nueng"
        Case 2: GetDigit = "Song"
        Case 3: GetDigit = "Sam"
        Case 4: GetDigit = "See"
        Case 5: GetDigit = "Ha"
        Case 6: GetDigit = "Hok"
        Case 7: GetDigit = "Jed"
        Case 8: GetDigit = "Pad"
        Case 9: GetDigit = "Kao"
        Case Else: GetDigit = ""
    End Select
End Function
ถ้าเป็นภาษาคาราโอเกะก็อโอเคครับท่านอาจารย์ แต่ผมต้องเปลี่ยนดั้่งนี้ครับ
Nueng เปลี่ยนเป็น sobj'
Ed เปลี่ยนเป็น gvaf

เมื่อเปลียนสองตัวนี้อ่านออกมาไม่ถูกต้องแล้วครับ

Re: สูครแปงตัวเลขเป็นคำ

Posted: Wed Jan 06, 2021 7:13 am
by snasui
:D ปรับ Code มาเองก่อนแล้วแนบมาในไฟล์ จะได้สะดวกในการช่วยเหลือของเพื่อนสมาชิกครับ

Re: สูครแปงตัวเลขเป็นคำ

Posted: Wed Jan 06, 2021 7:20 am
by วังวู ช่ง
วังวู ช่ง wrote: Wed Jan 06, 2021 7:05 am
snasui wrote: Tue Jan 05, 2021 9:09 pm :D ลองนำ Code นี้ไปปรับดูครับ

Code: Select all

Option Explicit

'Main Function
Function SpellNumber(ByVal MyNumber)
    Dim Bahts, Stangs, Temp1, Temp2
    Dim DecimalPlace, Count, t As Variant
    ReDim Place(9) As String
    Place(2) = " Lan "
    Place(3) = " Lan "
    Place(4) = " Lan "
    Place(5) = " Lan "
    ' String representation of amount.
    MyNumber = Trim(Str(MyNumber))
    ' Position of decimal place 0 if none.
    DecimalPlace = InStr(MyNumber, ".")
    ' Convert Stangs and set MyNumber to Baht amount.
    If DecimalPlace > 0 Then
        Stangs = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    Count = 1
    Do While MyNumber <> ""
        Temp1 = GetHundreds(Right(MyNumber, 3))
        If Len(MyNumber) > 3 Then
            Temp2 = GetHundreds1(Right(Left(MyNumber, Len(MyNumber) - 3), 3))
        Else
            Temp2 = ""
        End If
        If Temp1 <> "" Then Bahts = Temp1 & Place(Count) & Bahts
        If Temp2 <> "" Then Bahts = Temp2 & Bahts
        If Len(MyNumber) > 6 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 6)
        Else
            MyNumber = ""
        End If
        Count = Count + 1
    Loop
    Select Case Bahts
    Case ""
        Bahts = "Soon"
    Case "Nueng"
        Bahts = "Nueng"
    Case Else
        If Right(Bahts, 6) = " Nueng" Then
            t = Split(Application.Trim(Bahts), " ")
            If InStr(t(UBound(t) - 1), "sib") Or InStr(t(UBound(t) - 1), "Xao") Then
                Bahts = Left(Bahts, Len(Bahts) - 6) & " Ed"
            Else
                Bahts = Left(Bahts, Len(Bahts) - 6) & " Nueng"
            End If
        Else
            Bahts = Bahts
        End If
    End Select
        
    Select Case Stangs
        Case ""
            Stangs = ""
        Case "Nueng"
            Stangs = " Nueng"
        Case Else
            Stangs = " " & Stangs & " Stangs"
    End Select
    SpellNumber = Bahts & Stangs
End Function

' Converts a number from 100-999 into text
Function GetHundreds1(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    ' Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & " San "
    End If
    ' Convert the tens and ones place.
'    If Mid(MyNumber, 2, 1) <> "0" Then
'        Result = Result & GetDigit(Mid(MyNumber, 2, 1)) & " Muen "
'    End If
    If Mid(MyNumber, 2, 2) <> "00" Then
        Result = Result & GetTens(Mid(MyNumber, 2, 2)) & " Pan "
    End If
    GetHundreds1 = Result
End Function
' Converts a number from 100-999 into text
Function GetHundreds(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    ' Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & " Roi "
    End If
    ' Convert the tens and ones place.
    If Mid(MyNumber, 2, 1) <> "0" Then
        Result = Result & GetTens(Mid(MyNumber, 2))
    Else
        Result = Result & GetDigit(Mid(MyNumber, 3))
    End If
    GetHundreds = Result
End Function

' Converts a number from 10 to 99 into text.
Function GetTens(TensText)
    Dim Result As String
    Result = "" ' Null out the temporary function value.
    If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
        Select Case Val(TensText)
            Case 10: Result = "Sib"
            Case 11: Result = "Sib-ed"
            Case 12: Result = "Sibsong"
            Case 13: Result = "Sibsam"
            Case 14: Result = "Sibsee"
            Case 15: Result = "Sibha"
            Case 16: Result = "Sibhok"
            Case 17: Result = "Sibjed"
            Case 18: Result = "Sibpad"
            Case 19: Result = "Sibkao"
            Case Else
        End Select
    Else ' If value between 20-99...
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "Xao "
            Case 3: Result = "Samsib "
            Case 4: Result = "Seesib "
            Case 5: Result = "Hasib "
            Case 6: Result = "Hoksib "
            Case 7: Result = "Jedsib "
            Case 8: Result = "Padsib "
            Case 9: Result = "Kaosib "
            Case Else
        End Select
        Result = Result & GetDigit(Right(TensText, 1))  ' Retrieve ones place.
    End If
    GetTens = Result
End Function

' Converts a number from 1 to 9 into text.
Function GetDigit(Digit)
    Select Case Val(Digit)
        Case 1: GetDigit = "Nueng"
        Case 2: GetDigit = "Song"
        Case 3: GetDigit = "Sam"
        Case 4: GetDigit = "See"
        Case 5: GetDigit = "Ha"
        Case 6: GetDigit = "Hok"
        Case 7: GetDigit = "Jed"
        Case 8: GetDigit = "Pad"
        Case 9: GetDigit = "Kao"
        Case Else: GetDigit = ""
    End Select
End Function
ปรับคืนได้แล้วเดีอาจารย์ ขอบคุณมากๆ :D :D :D :thup: :thup: :thup: :cp: :cp: :cp:

Re: สูครแปงตัวเลขเป็นคำ

Posted: Wed Jan 06, 2021 7:26 am
by วังวู ช่ง
21,452,321 Xao Nueng Lan See San Hasib Song Pan Sam Roi Xao Ed
อ่านตัวนี้ผิดครับท่านอาจารย์ ผมกำลังตรวจครับ

Re: สูครแปงตัวเลขเป็นคำ

Posted: Wed Jan 06, 2021 8:03 am
by วังวู ช่ง
วังวู ช่ง wrote: Wed Jan 06, 2021 7:26 am 21,452,321 Xao Nueng Lan See San Hasib Song Pan Sam Roi Xao Ed
อ่านตัวนี้ผิดครับท่านอาจารย์ ผมกำลังตรวจครับ

Re: สูครแปงตัวเลขเป็นคำ

Posted: Wed Jan 06, 2021 8:46 am
by วังวู ช่ง
21,000,000
31,000,000
41,000,000
.
.
.
91,000,000
อ่านผิดครับอาจารย อ่านว่า ชาวหนึ่งล้านครับ ไม่รู้ว่าจะปรับตรงไหนเลย

Re: สูครแปงตัวเลขเป็นคำ

Posted: Wed Jan 06, 2021 7:38 pm
by snasui
:D ที่ถูกอ่านว่าอย่างไร เขียนคำอ่านที่ถูกต้องเปรียบเทียบมาในไฟล์ด้วยทุก ๆ ค่าที่จะใช้ทดสอบครับ

Re: สูครแปงตัวเลขเป็นคำ

Posted: Wed Jan 06, 2021 8:10 pm
by วังวู ช่ง
snasui wrote: Wed Jan 06, 2021 7:38 pm :D ที่ถูกอ่านว่าอย่างไร เขียนคำอ่านที่ถูกต้องเปรียบเทียบมาในไฟล์ด้วยทุก ๆ ค่าที่จะใช้ทดสอบครับ
ยังเพียงแค่หลักล้าน อ่านผิดครับอาจารย์ แต่ 21,000,000-91,000,000 ครับคือ
21,000,000
31,000,000
41,000,000
51,000,000
61,000,000
71,000,000
81,000,000
91,000,000
เหลือนั้นถูกหมดแล้วครับ ดูใน sheet1 ครับผม

Re: สูครแปงตัวเลขเป็นคำ

Posted: Thu Jan 07, 2021 6:47 am
by snasui
:D ตัวอย่างการปรับ Code ที่ Function GetTents ครับ

Code: Select all

Function GetTens(TensText)
    Dim Result As String
    Result = "" ' Null out the temporary function value.
    If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
        Select Case Val(TensText)
            Case 10: Result = "Sib"
            Case 11: Result = "Sib-ed"
            Case 12: Result = "Sibsong"
            Case 13: Result = "Sibsam"
            Case 14: Result = "Sibsee"
            Case 15: Result = "Sibha"
            Case 16: Result = "Sibhok"
            Case 17: Result = "Sibjed"
            Case 18: Result = "Sibpad"
            Case 19: Result = "Sibkao"
            Case Else
        End Select
    Else ' If value between 20-99...
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "Xao "
            Case 3: Result = "Samsib "
            Case 4: Result = "Seesib "
            Case 5: Result = "Hasib "
            Case 6: Result = "Hoksib "
            Case 7: Result = "Jedsib "
            Case 8: Result = "Padsib "
            Case 9: Result = "Kaosib "
            Case Else
        End Select
        Result = Result & GetDigit(Right(TensText, 1))  ' Retrieve ones place.
    End If
    GetTens = IIf(Result = "Nueng", "Nueng", Replace(Result, "Nueng", "Ed"))
End Function

Re: สูครแปงตัวเลขเป็นคำ

Posted: Thu Jan 07, 2021 8:28 am
by วังวู ช่ง
snasui wrote: Thu Jan 07, 2021 6:47 am :D ตัวอย่างการปรับ Code ที่ Function GetTents ครับ

Code: Select all

Function GetTens(TensText)
    Dim Result As String
    Result = "" ' Null out the temporary function value.
    If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
        Select Case Val(TensText)
            Case 10: Result = "Sib"
            Case 11: Result = "Sib-ed"
            Case 12: Result = "Sibsong"
            Case 13: Result = "Sibsam"
            Case 14: Result = "Sibsee"
            Case 15: Result = "Sibha"
            Case 16: Result = "Sibhok"
            Case 17: Result = "Sibjed"
            Case 18: Result = "Sibpad"
            Case 19: Result = "Sibkao"
            Case Else
        End Select
    Else ' If value between 20-99...
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "Xao "
            Case 3: Result = "Samsib "
            Case 4: Result = "Seesib "
            Case 5: Result = "Hasib "
            Case 6: Result = "Hoksib "
            Case 7: Result = "Jedsib "
            Case 8: Result = "Padsib "
            Case 9: Result = "Kaosib "
            Case Else
        End Select
        Result = Result & GetDigit(Right(TensText, 1))  ' Retrieve ones place.
    End If
    GetTens = IIf(Result = "Nueng", "Nueng", Replace(Result, "Nueng", "Ed"))
End Function
ขอบคุณท่านอาจารย์มากๆครับ ได้ตามต้องการเลยครับ :D :D :D :thup: :thup: :thup: :cp: :cp: :cp: