Office中国论坛/Access中国论坛

标题: 如何将数字转换成英文的大写? [打印本页]

作者: zxcnet    时间: 2003-10-11 17:52
标题: 如何将数字转换成英文的大写?
我是做货代的,在打印提单时经常要将数字转换成英文大写格式,每次都手动太麻烦了,请问有没有什么函数或者控件可是实现自动转换?谢谢啊
作者: ADAM    时间: 2003-10-11 18:22
你搜索一下吧,好像論壇上有的,具體在哪,你要自已找找
我好像昨天還在accxp上看到,也有
作者: andymark    时间: 2003-10-11 18:33
數字轉英文(金額轉換)源碼
Public Function x(num As String) As String
Select Case num
Case "0": x = ""
Case "1": x = "one"
Case "2": x = "two"
Case "3": x = "three"
Case "4": x = "four"
Case "5": x = "five"
Case "6": x = "six"
Case "7": x = "seven"
Case "8": x = "eight"
Case "9": x = "nine"
End Select
End Function
Public Function xxa(num As String) As String
Select Case num
Case "2": xxa = "twenty"
Case "3": xxa = "thirty"
Case "4": xxa = "forty"
Case "5": xxa = "fifty"
Case "6": xxa = "sixty"
Case "7": xxa = "seventy"
Case "8": xxa = "eighty"
Case "9": xxa = "ninety"
End Select
End Function
Public Function xxb(num As String) As String
Select Case num
Case "10": xxb = "ten"
Case "11": xxb = "eleven"
Case "12": xxb = "twelve"
Case "13": xxb = "thirteen"
Case "14": xxb = "fourteen"
Case "15": xxb = "fivteen"
Case "16": xxb = "sixteen"
Case "17": xxb = "seventeen"
Case "18": xxb = "eighteen"
Case "19": xxb = "nineteen"
End Select
End Function
Public Function xx_2(num As String) As String
If CInt(num) < 10 Then
xx_2 = x(num)
Else
If CInt(num) < 20 Then
xx_2 = xxb(num)
Else
xx_2 = xxa(Left(num, 1)) + " " + x(Right(num, 1))
End If
End If
End Function
Public Function xx_3(num As String) As String
If IsNull(num) Then
Exit Function
End If

If CInt(num) < 999 And CInt(num) >= 100 Then
xx_3 = x(Left(num, 1)) + " hundred " + xx_2(Right(num, 2))
Else
If CInt(num) < 100 Then
xx_3 = xx_2(num)
End If
End If
End Function
Public Function xx_m(num As Currency) As String

Dim str_dollars As String
Dim str_cents As String
Dim str_dollars_len As Integer
Dim str_result As String
str_cents = Right(Format(num, ".00"), 2)
str_dollars = Left(Format(num, ".00"), Len(Format(num, ".00")) - 3)
str_dollars_len = Len(str_dollars)

If str_dollars_len <= 3 Then
xx_m = xx_3(str_dollars) + " dollars and " + xx_3(str_cents) + " cents"
Else
If (str_dollars_len Mod 3) <> 0 Then
If str_dollars_len < 6 And str_dollars_len <> 6 Then
xx_m = xx_3(Left(str_dollars, str_dollars_len Mod 3)) + " thousand " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1, 3)) + " dollars and " + xx_3(str_cents) + " cents"
Else
If str_dollars_len < 9 And str_dollars_len <> 9 Then
xx_m = xx_3(Left(str_dollars, str_dollars_len Mod 3)) + " million " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1, 3)) + " thousand " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3, 3)) + " dollars and " + xx_3(str_cents) + " cents"
Else
If str_dollars_len < 12 And str_dollars <> 12 Then
xx_m = xx_3(Left(str_dollars, str_dollars_len Mod 3)) + " billion " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1, 3)) + " million " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3, 3)) + " thousand " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3 + 3 + 3, 3)) + " dollars and " + xx_3(str_cents) + " cents"
Else
If str_dollars_len < 15 And str_dollars <> 15 Then
xx_m = xx_3(Left(str_dollars, str_dollars_len Mod 3)) + " trillion " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1, 3)) + " billion " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3, 3)) + " million " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3 + 3, 3)) + " thousand " + xx_3(Mid(str_dollars, (str_dollars_len Mod 3) + 1 + 3 + 3 + 3, 3)) + " dollars and " + xx_3(str_cents) + " cents "
End If
End If
End If
End If
End If
End If
'-------------------------------------------------
If (str_dollars_len > 3) And ((str_dollars_len Mod 3) = 0) Then
If str_dollars_len = 6 Then
xx_m = xx_3(Left(str_dollars, 3)) + " thousand " + xx_3(Mid(str_dollars, 1 + 3, 3)) + " dollars and " + xx_3(str_cents) + " cents"
Else
If str_dollars_len = 9 Then
xx_m = xx_3(Left(str_dollars, 3)) + " million " + xx_3(Mid(str_dollars, 1 + 3, 3)) + " thousand " + xx_3(Mid(str_dollars, 1 + 3 + 3, 3)) + " dollars and " + xx_3(str_cents) + " cents"
Else
If str_dollars_len = 12 Then
xx_m = xx_3(Left(str_dollars, 3)) + " billion " + xx_3(Mid(str_dollars, 1 + 3, 3)) + " million " + xx_3(Mid(str_dollars, 1 + 3 + 3, 3)) + " thousand " + xx_3(Mid(str
作者: zxcnet    时间: 2003-10-11 18:36
谢谢andymark,我去试试
作者: zxcnet    时间: 2003-10-11 18:39
遇到问题了,我是个新手有点搞不清楚,源码中的x,x_2,x_3,x_m,xxa,xxb都代表什么意思啊
作者: andymark    时间: 2003-10-11 18:54
定义数的位置




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3