Code convert

Résolu/Fermé
mimoudiligence - 1 juil. 2016 à 19:31
 mimoudiligence - 2 juil. 2016 à 16:03
Bonjour,
j'ai introduit ce module sur alt + f11 l'excel converti les chiffre en lettre sur la feuille excel mais comme 100 il mentionne un cent 1000 il mentionne un mille,

ex 14100 quatorze mille un cent dinars, au lieu de quatorze mille cent dinars..
merci de m'aider a modifier ce module



Option Explicit
'Main Function
Function SpellNumber(ByVal MyNumber)
Dim Dinars, Cents, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Mille "
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 dinar 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 Dinars = Temp & Place(Count) & Dinars
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Dinars
Case ""
Dinars = "Zero Dinars"
Case "One"
Dinars = "Un Dinar"
Case Else
Dinars = Dinars & " Dinars"
End Select
Select Case Cents
Case ""
Cents = " et Zero Centimes"
Case "Un"
Cents = " et Un Centime"
Case Else
Cents = " et " & Cents & " Centimes"
End Select
SpellNumber = Dinars & 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 = "Un"
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


A voir également:

1 réponse

gbinforme Messages postés 14946 Date d'inscription lundi 18 octobre 2004 Statut Contributeur Dernière intervention 24 juin 2020 4 700
1 juil. 2016 à 23:49
Bonjour,

Essaies de changer cette ligne ainsi :
Case 1: GetDigit = "" 
0
mimoudiligence
2 juil. 2016 à 16:03
merci ça bien marché
0