老兄:是翻译成英文 如: 1--> one 2--> two .... 100 --> one hundred ....
转贴自planet source code. Public Function AlphaNumber(resultis, ByVal num As Double, style As String) 'This was created by Jason Khanlar 'Please, since this took a lot of effort ' give me credit, 'if you distribute this in a program. 'Only numbers between '-999999999999999 and 999999999999999 'can be used. 'To use this function - 'Call AlphaNumber(n,"counting") 'where n is a number in the range above. ' ' Example - AlphaNumber(451,"counting") ' returns ' four hundred fifty-one ' Example 2 - AlphaNumber(-42,"counting" ' ) returns ' negative fourty-two 'Call AlphaNumber(n'"single") 'where n is a number in the range above. ' ' Example - AlphaNumber(451,"single") re ' turns ' four five one ' Example 2 - AlphaNumber(-42,"single") ' returns ' negative four two 'Near the bottom are two lines that come ' up with the result 'Change them according to where you want ' the results to be shown 'They should be easy to find. Dim counter%, final$, negative$, previous%, tempnum%, tempnumstr$ counter = 0 final = "" If Left(num, 1) = "-" Then negative = "negative " Else negative = "" End If If style = "counting" Then Do counter = counter + 1 num = Replace(num, "-", "") If counter <= Len(Replace(num, Chr(13), "")) Then tempnum = Left(Right(num, counter), 1) If counter = 1 Or counter = 3 Or counter = 4 Or counter = 6 Or counter = 7 Or counter = 9 Or counter = 10 Or counter = 12 Or counter = 13 Or counter = 15 Then If counter = 1 Then If Left(Right(num, Int(counter + 1)), 1) = 1 And Len(Replace(num, Chr(13), "")) <> 1 Then previous = tempnum Goto afterprevious End If End If If tempnum = 1 Then tempnumstr = "one" ElseIf tempnum = 2 Then tempnumstr = "two" ElseIf tempnum = 3 Then tempnumstr = "three" ElseIf tempnum = 4 Then tempnumstr = "four" ElseIf tempnum = 5 Then tempnumstr = "five" ElseIf tempnum = 6 Then tempnumstr = "six" ElseIf tempnum = 7 Then tempnumstr = "seven" ElseIf tempnum = 8 Then tempnumstr = "eight" ElseIf tempnum = 9 Then tempnumstr = "nine" ElseIf tempnum = 0 Then tempnumstr = "" End If If (counter = 3 Or counter = 6 Or counter = 9 Or counter = 12 Or counter = 15) And tempnum <> 0 Then tempnumstr = tempnumstr & " hundred " ElseIf counter = 4 And tempnum <> 0 Then If Left(Right(num, 5), 1) = 1 And Right(num, 5) <> Right(num, 4) Then tempnumstr = "" Else tempnumstr = tempnumstr & " thousand " End If ElseIf counter = 6 And tempnum <> 0 Then tempnumstr = tempnumstr & " hundred thousand " ElseIf counter = 7 And tempnum <> 0 Then If Left(Right(num, 8), 1) = 1 And Right(num, 8) <> Right(num, 7) Then tempnumstr = "" Else tempnumstr = tempnumstr & " million " End If ElseIf counter = 10 And tempnum <> 0 Then If Left(Right(num, 11), 1) = 1 And Right(num, 11) <> Right(num, 10) Then tempnumstr = "" Else tempnumstr = tempnumstr & " billion " End If ElseIf counter = 13 And tempnum <> 0 Then If Left(Right(num, 14), 1) = 1 And Right(num, 14) <> Right(num, 13) Then tempnumstr = "" Else tempnumstr = tempnumstr & " trillion " End If End If ElseIf counter = 2 Or counter = 5 Or counter = 8 Or counter = 11 Or counter = 14 Then If tempnum = 1 Then If previous = 1 Then tempnumstr = "eleven" ElseIf previous = 2 Then tempnumstr = "twelve" ElseIf previous = 3 Then tempnumstr = "thirteen" ElseIf previous = 4 Then tempnumstr = "fourteen" ElseIf previous = 5 Then tempnumstr = "fifteen" ElseIf previous = 6 Then tempnumstr = "sixteen" ElseIf previous = 7 Then tempnumstr = "seventeen" ElseIf previous = 8 Then tempnumstr = "eighteen" ElseIf previous = 9 Then tempnumstr = "nineteen" ElseIf previous = 0 Then tempnumstr = "ten" End If If counter = 5 Then tempnumstr = tempnumstr & " thousand " Goto final ElseIf counter = 8 Then tempnumstr = tempnumstr & " million " Goto final ElseIf counter = 11 Then tempnumstr = tempnumstr & " billion " Goto final ElseIf counter = 14 Then tempnumstr = tempnumstr & " trillion " Goto final End If ElseIf tempnum = 2 Then tempnumstr = "twenty-" ElseIf tempnum = 3 Then tempnumstr = "thirty-" ElseIf tempnum = 4 Then tempnumstr = "forty-" ElseIf tempnum = 5 Then tempnumstr = "fifty-" ElseIf tempnum = 6 Then tempnumstr = "sixty-" ElseIf tempnum = 7 Then tempnumstr = "seventy-" ElseIf tempnum = 8 Then tempnumstr = "eighty-" ElseIf tempnum = 9 Then tempnumstr = "ninety-" ElseIf tempnum = 0 Then tempnumstr = "" End If End If final: final = tempnumstr & final previous: previous = tempnum afterprevious: Else If Right(final, 1) = "-" Then final = Left(final, Int(Len(final) - 1)) End If ' Here's the first one ' Change the next line to return the res ' ults to where you want Text2.Text = negative & Trim(final) Exit Function End If Loop Form1.Text2.Text = final ElseIf style = "single" Then Do counter = counter + 1 num = Replace(num, "-", "") If counter <= Len(Replace(num, Chr(13), "")) Then tempnum = Left(Right(num, counter), 1) If tempnum = 1 Then tempnumstr = "one " ElseIf tempnum = 2 Then tempnumstr = "two " ElseIf tempnum = 3 Then tempnumstr = "three " ElseIf tempnum = 4 Then tempnumstr = "four " ElseIf tempnum = 5 Then tempnumstr = "five " ElseIf tempnum = 6 Then tempnumstr = "six " ElseIf tempnum = 7 Then tempnumstr = "seven " ElseIf tempnum = 8 Then tempnumstr = "eight " ElseIf tempnum = 9 Then tempnumstr = "nine " ElseIf tempnum = 0 Then tempnumstr = "zero " End If final = tempnumstr & final Else ' Here's he second one ' Change the next line to return the res ' ults to where you want Text2.Text = negative & Trim(final) Exit Function End If Loop End If End Function
如: 1--> one
2--> two
....
100 --> one hundred
....
转贴自planet source code.
Public Function AlphaNumber(resultis, ByVal num As Double, style As String)
'This was created by Jason Khanlar
'Please, since this took a lot of effort
' give me credit,
'if you distribute this in a program.
'Only numbers between
'-999999999999999 and 999999999999999
'can be used.
'To use this function -
'Call AlphaNumber(n,"counting")
'where n is a number in the range above.
'
' Example - AlphaNumber(451,"counting")
' returns
' four hundred fifty-one
' Example 2 - AlphaNumber(-42,"counting"
' ) returns
' negative fourty-two
'Call AlphaNumber(n'"single")
'where n is a number in the range above.
'
' Example - AlphaNumber(451,"single") re
' turns
' four five one
' Example 2 - AlphaNumber(-42,"single")
' returns
' negative four two
'Near the bottom are two lines that come
' up with the result
'Change them according to where you want
' the results to be shown
'They should be easy to find.
Dim counter%, final$, negative$, previous%, tempnum%, tempnumstr$
counter = 0
final = ""
If Left(num, 1) = "-" Then
negative = "negative "
Else
negative = ""
End If
If style = "counting" Then
Do
counter = counter + 1
num = Replace(num, "-", "")
If counter <= Len(Replace(num, Chr(13), "")) Then
tempnum = Left(Right(num, counter), 1)
If counter = 1 Or counter = 3 Or counter = 4 Or counter = 6 Or counter = 7 Or counter = 9 Or counter = 10 Or counter = 12 Or counter = 13 Or counter = 15 Then
If counter = 1 Then
If Left(Right(num, Int(counter + 1)), 1) = 1 And Len(Replace(num, Chr(13), "")) <> 1 Then
previous = tempnum
Goto afterprevious
End If
End If
If tempnum = 1 Then
tempnumstr = "one"
ElseIf tempnum = 2 Then
tempnumstr = "two"
ElseIf tempnum = 3 Then
tempnumstr = "three"
ElseIf tempnum = 4 Then
tempnumstr = "four"
ElseIf tempnum = 5 Then
tempnumstr = "five"
ElseIf tempnum = 6 Then
tempnumstr = "six"
ElseIf tempnum = 7 Then
tempnumstr = "seven"
ElseIf tempnum = 8 Then
tempnumstr = "eight"
ElseIf tempnum = 9 Then
tempnumstr = "nine"
ElseIf tempnum = 0 Then
tempnumstr = ""
End If
If (counter = 3 Or counter = 6 Or counter = 9 Or counter = 12 Or counter = 15) And tempnum <> 0 Then
tempnumstr = tempnumstr & " hundred "
ElseIf counter = 4 And tempnum <> 0 Then
If Left(Right(num, 5), 1) = 1 And Right(num, 5) <> Right(num, 4) Then
tempnumstr = ""
Else
tempnumstr = tempnumstr & " thousand "
End If
ElseIf counter = 6 And tempnum <> 0 Then
tempnumstr = tempnumstr & " hundred thousand "
ElseIf counter = 7 And tempnum <> 0 Then
If Left(Right(num, 8), 1) = 1 And Right(num, 8) <> Right(num, 7) Then
tempnumstr = ""
Else
tempnumstr = tempnumstr & " million "
End If
ElseIf counter = 10 And tempnum <> 0 Then
If Left(Right(num, 11), 1) = 1 And Right(num, 11) <> Right(num, 10) Then
tempnumstr = ""
Else
tempnumstr = tempnumstr & " billion "
End If
ElseIf counter = 13 And tempnum <> 0 Then
If Left(Right(num, 14), 1) = 1 And Right(num, 14) <> Right(num, 13) Then
tempnumstr = ""
Else
tempnumstr = tempnumstr & " trillion "
End If
End If
ElseIf counter = 2 Or counter = 5 Or counter = 8 Or counter = 11 Or counter = 14 Then
If tempnum = 1 Then
If previous = 1 Then
tempnumstr = "eleven"
ElseIf previous = 2 Then
tempnumstr = "twelve"
ElseIf previous = 3 Then
tempnumstr = "thirteen"
ElseIf previous = 4 Then
tempnumstr = "fourteen"
ElseIf previous = 5 Then
tempnumstr = "fifteen"
ElseIf previous = 6 Then
tempnumstr = "sixteen"
ElseIf previous = 7 Then
tempnumstr = "seventeen"
ElseIf previous = 8 Then
tempnumstr = "eighteen"
ElseIf previous = 9 Then
tempnumstr = "nineteen"
ElseIf previous = 0 Then
tempnumstr = "ten"
End If
If counter = 5 Then
tempnumstr = tempnumstr & " thousand "
Goto final
ElseIf counter = 8 Then
tempnumstr = tempnumstr & " million "
Goto final
ElseIf counter = 11 Then
tempnumstr = tempnumstr & " billion "
Goto final
ElseIf counter = 14 Then
tempnumstr = tempnumstr & " trillion "
Goto final
End If
ElseIf tempnum = 2 Then
tempnumstr = "twenty-"
ElseIf tempnum = 3 Then
tempnumstr = "thirty-"
ElseIf tempnum = 4 Then
tempnumstr = "forty-"
ElseIf tempnum = 5 Then
tempnumstr = "fifty-"
ElseIf tempnum = 6 Then
tempnumstr = "sixty-"
ElseIf tempnum = 7 Then
tempnumstr = "seventy-"
ElseIf tempnum = 8 Then
tempnumstr = "eighty-"
ElseIf tempnum = 9 Then
tempnumstr = "ninety-"
ElseIf tempnum = 0 Then
tempnumstr = ""
End If
End If
final:
final = tempnumstr & final
previous:
previous = tempnum
afterprevious:
Else
If Right(final, 1) = "-" Then
final = Left(final, Int(Len(final) - 1))
End If
' Here's the first one
' Change the next line to return the res
' ults to where you want
Text2.Text = negative & Trim(final)
Exit Function
End If
Loop
Form1.Text2.Text = final
ElseIf style = "single" Then
Do
counter = counter + 1
num = Replace(num, "-", "")
If counter <= Len(Replace(num, Chr(13), "")) Then
tempnum = Left(Right(num, counter), 1)
If tempnum = 1 Then
tempnumstr = "one "
ElseIf tempnum = 2 Then
tempnumstr = "two "
ElseIf tempnum = 3 Then
tempnumstr = "three "
ElseIf tempnum = 4 Then
tempnumstr = "four "
ElseIf tempnum = 5 Then
tempnumstr = "five "
ElseIf tempnum = 6 Then
tempnumstr = "six "
ElseIf tempnum = 7 Then
tempnumstr = "seven "
ElseIf tempnum = 8 Then
tempnumstr = "eight "
ElseIf tempnum = 9 Then
tempnumstr = "nine "
ElseIf tempnum = 0 Then
tempnumstr = "zero "
End If
final = tempnumstr & final
Else
' Here's he second one
' Change the next line to return the res
' ults to where you want
Text2.Text = negative & Trim(final)
Exit Function
End If
Loop
End If
End Function
还有一点小问题,不能翻译带小数点的