主頁 > 知識庫 > VBS 數(shù)字轉(zhuǎn)英文代碼

VBS 數(shù)字轉(zhuǎn)英文代碼

熱門標簽:百度地圖標注怎么卸載 海外美發(fā)店地圖標注 外呼營銷下單系統(tǒng) 前鋒辦理400電話申請 辦理膠州400電話財稅 新密防封卡外呼系統(tǒng)違法嗎 陜西高頻外呼回撥系統(tǒng)哪家好 加盟電銷機器人好的品牌 打電話的外呼系統(tǒng)貴不貴
如何創(chuàng)建名為 SpellNumber 的示例函數(shù)
啟動 Microsoft Excel。
按 Alt+F11 啟動 Visual Basic 編輯器。
在“插入”菜單上,單擊“模塊”。
在模塊表中鍵入下面的代碼。
復制代碼 代碼如下:

Option Explicit
'Main Function
Function SpellNumber(ByVal MyNumber)
Dim Dollars, Cents, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "
' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
DecimalPlace = InStr(MyNumber, ".")
' Convert cents and set 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)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Dollars
Case ""
Dollars = "No Dollars"
Case "One"
Dollars = "One Dollar"
Case Else
Dollars = Dollars " Dollars"
End Select
Select Case Cents
Case ""
Cents = " and No Cents"
Case "One"
Cents = " and One Cent"
Case Else
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
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))
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 = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
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 = "One"
Case 2: GetDigit = "Two"
Case 3: GetDigit = "Three"
Case 4: GetDigit = "Four"
Case 5: GetDigit = "Five"
Case 6: GetDigit = "Six"
Case 7: GetDigit = "Seven"
Case 8: GetDigit = "Eight"
Case 9: GetDigit = "Nine"
Case Else: GetDigit = ""
End Select
End Function

如何使用 SpellNumber 示例函數(shù)
要使用該示例函數(shù)將某數(shù)字更改為書面文本,請使用下列示例中演示的方法之一:
回到頂端
方法 1:直接輸入
通過將下面的公式輸入單元格中,可以將 32.50 更改為“Thirty Two Dollars and Fifty Cents”:
=SpellNumber(32.50)
回到頂端
方法 2:單元格引用
可以引用工作簿中的其他單元格。例如,在單元格 A1 中輸入數(shù)字 32.50,然后在另一單元格中鍵入下面的公式:
=SpellNumber(A1)
回到頂端
方法 3:粘貼函數(shù)或插入函數(shù)
可以使用“粘貼函數(shù)”(在 Excel 2000 和 Excel 2002 中)或“插入函數(shù)”(在 Excel 2003 中)來將自定義函數(shù)輸入工作表中。

標簽:梅州 牡丹江 四平 武威 河南 阜陽 咸陽 伊春

巨人網(wǎng)絡通訊聲明:本文標題《VBS 數(shù)字轉(zhuǎn)英文代碼》,本文關(guān)鍵詞  VBS,數(shù)字,轉(zhuǎn),英文,代碼,VBS,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《VBS 數(shù)字轉(zhuǎn)英文代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于VBS 數(shù)字轉(zhuǎn)英文代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章