VB将数字翻译成英文

更新时间:2023-05-18 13:42:24 阅读: 评论:0

下面是一个将阿拉伯数字转换成英文说法的VB代码,源程序默认将小数点后面也翻译成英文
附源代码:
'****************' Main Function *'****************
Function SpellNumber(ByVal MyNumber)
    Dim Dollars, Cents, Temp
    Dim DecimalPlace, Count
    ReDim Place(9) As String
    Application.Volatile True
    Place(2) = " Thousand "
    Select Ca Cents
        Ca """"
    Place(3) = " Million "
    Place(4) = " Billion "
    Place(5) = " Trillion "     ' String reprentation of amount
    MyNumber = Trim(Str(MyNumber))     ' Position of decimal place 0 if nonemoreorless
    DecimalPlace = InStr(MyNumber, ".")
    'Convert cents and t MyNumber to dollar amount
    If DecimalPlace > 0 Then
        Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
        End If
    Count = 1
    Do While MyNumber <> ""
      Temp = GetHundreds(Right(MyNumber, 3))
      If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
          If Len(MyNumber) > 3 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 3)布基纳法索英文
            El
            MyNumber = ""
            End Ifthe way of life
            Count = Count + 1
            Loop
    Select Ca Dollars
        Ca ""
            Dollars = "No Dollars"
        Ca "One"
            Dollars = "One Dollar"
        Ca El
            Dollars = Dollars & " Dollars"
    End Select
            Cents = " and No Cents"
        Ca "One"
            Cents = " and One Cent"
        Ca El
            Cents = " and " & Cents & " Cents"
    End Select
    SpellNumber = Dollars & Cents
    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
babysteps        Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
        End If
    'Convert the tens and ones place
    If Mid(MyNumber, 2, 1) <> "0" Then
        Result = Result & GetTens(Mid(MyNumber, 2))
        El
        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 Ca Val(TensText)
        Ca 10: Result = "Ten"subjectto
            Ca 11: Result = "Eleven"
            Ca 12: Result = "Twelve"
            Ca 13: Result = "Thirteen"
            Ca 14: Result = "Fourteen"
            Ca 15: Result = "Fifteen"
            Ca 16: Result = "Sixteen"澳大利亚百年洪水
            Ca 17: Result = "Seventeen"
            Ca 18: Result = "Eighteen"
            Ca 19: Result = "Nineteen"
            Ca El
            End Select
      El                                 ' If value between 20-99
        Select Ca Val(Left(TensText, 1))
            Ca 2: Result = "Twenty "
            Ca 3: Result = "Thirty "
            Ca 4: Result = "Forty "
            Ca 5: Result = "Fifty "
            Ca 6: Result = "Sixty "
            Ca 7: Result = "Seventy "
            Ca 8: Result = "Eighty "
            Ca 9: Result = "Ninety "
            Ca El
        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 Ca Val(Digit)
        Ca 1: GetDigit = "One"
胶水英文nss        Ca 2: GetDigit = "Two"
        Ca 3: GetDigit = "Three"
        Ca 4: GetDigit = "Four"
        Ca 5: GetDigit = "Five"
        Ca 6: GetDigit = "Six"
        Ca 7: GetDigit = "Seven"
        Ca 8: GetDigit = "Eight"
        Ca 9: GetDigit = "Nine"
        Ca El: GetDigit = ""

本文发布于:2023-05-18 13:42:24,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/113323.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图