tulipansell
XLDnaute Nouveau
erreure dans : - 1 et 1000 DA n'affiche pas
- ne reconnais pas la décimale : 01 CTS
- de 71 DA à 76 DA et 81 DA
- de 91 DA à 96 DA
voici la fonction :
Function SpellNumber(ByVal MyNumber)
Dim Dollars, Cents, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Mille "
Place(3) = " Million"
Place(4) = " Milliard "
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 = " dinars algériens "
Case "One"
Dollars = " dinars algériens "
Case Else
Dollars = Dollars & " dinars algériens "
End Select
Select Case Cents
Case ""
Cents = " et zero centime "
Case "One"
Cents = " et zero un centime "
Case Else
Cents = " et " & Cents & " centime "
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)) & " cent "
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 = "dix"
Case 11: Result = "onze"
Case 12: Result = "douze"
Case 13: Result = "treize"
Case 14: Result = "quatorze"
Case 15: Result = "quinze"
Case 16: Result = "seize"
Case 17: Result = "dix sept"
Case 18: Result = "dix huit"
Case 19: Result = "dix neuf"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "vingt "
Case 3: Result = "trente "
Case 4: Result = "quarante "
Case 5: Result = "cinquante "
Case 6: Result = "soixante "
Case 7: Result = "soixante dix "
Case 8: Result = "quatre vingt "
Case 9: Result = "quatre vingt dix "
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 = ""
Case 2: GetDigit = "deux"
Case 3: GetDigit = "trois"
Case 4: GetDigit = "quatre"
Case 5: GetDigit = "cinq"
Case 6: GetDigit = "six"
Case 7: GetDigit = "sept"
Case 8: GetDigit = "huit"
Case 9: GetDigit = "neuf"
Case Else: GetDigit = ""
End Select
End Function
- ne reconnais pas la décimale : 01 CTS
- de 71 DA à 76 DA et 81 DA
- de 91 DA à 96 DA
voici la fonction :
Function SpellNumber(ByVal MyNumber)
Dim Dollars, Cents, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Mille "
Place(3) = " Million"
Place(4) = " Milliard "
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 = " dinars algériens "
Case "One"
Dollars = " dinars algériens "
Case Else
Dollars = Dollars & " dinars algériens "
End Select
Select Case Cents
Case ""
Cents = " et zero centime "
Case "One"
Cents = " et zero un centime "
Case Else
Cents = " et " & Cents & " centime "
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)) & " cent "
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 = "dix"
Case 11: Result = "onze"
Case 12: Result = "douze"
Case 13: Result = "treize"
Case 14: Result = "quatorze"
Case 15: Result = "quinze"
Case 16: Result = "seize"
Case 17: Result = "dix sept"
Case 18: Result = "dix huit"
Case 19: Result = "dix neuf"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "vingt "
Case 3: Result = "trente "
Case 4: Result = "quarante "
Case 5: Result = "cinquante "
Case 6: Result = "soixante "
Case 7: Result = "soixante dix "
Case 8: Result = "quatre vingt "
Case 9: Result = "quatre vingt dix "
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 = ""
Case 2: GetDigit = "deux"
Case 3: GetDigit = "trois"
Case 4: GetDigit = "quatre"
Case 5: GetDigit = "cinq"
Case 6: GetDigit = "six"
Case 7: GetDigit = "sept"
Case 8: GetDigit = "huit"
Case 9: GetDigit = "neuf"
Case Else: GetDigit = ""
End Select
End Function