1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| Dim U(20) As String
Dim D(11) As String
Private Function CtoL(Chiffre As String) As String
If Chiffre >= 1 And Chiffre <= 19 Then 'entre 1 et 20
CtoL = U(Chiffre)
Else
Select Case Len(Chiffre)
Case 2
If Mid(Chiffre, 1, 1) = 9 Or Mid(Chiffre, 1, 1) = 7 Then
If Chiffre = 80 Then
CtoL = "quatre-vingts"
Else
CtoL = D(Mid(Chiffre, 1, 1) - 1) & "-" & U(Mid(Chiffre, 2, 1) + 10)
End If
Else
If (Chiffre / 10 >= 2 And Chiffre Mod 10 = 0) Or (Chiffre / 10 <= 9 And Chiffre Mod 10 = 0) Then 'entre 20 ,30,...90
CtoL = D(Chiffre / 10) & "s"
Else
CtoL = D(Mid(Chiffre, 1, 1)) & "-" & U(Mid(Chiffre, 2, 1))
If U(Mid(Chiffre, 2, 1)) <> "0" Then
'Ctol = Replace(CtoL, " ", "-")
End If
End If
End If
Case 3
If Chiffre Mod 100 = 0 Then CtoL = IIf(Mid(Chiffre, 1, 1) = "1", " cent", U(Mid(Chiffre, 1, 1)) & " cents"): GoTo ici
CtoL = IIf(Mid(Chiffre, 1, 1) = 1, "cent", U(Mid(Chiffre, 1, 1)) & " cent")
If Mid(Chiffre, 2, 1) = 9 Or Mid(Chiffre, 2, 1) = 7 Then
CtoL = CtoL & " " & D(Mid(Chiffre, 2, 1) - 1) & " " & U(Mid(Chiffre, 3, 1) + 10)
ElseIf Mid(Chiffre, 2) >= 1 And Mid(Chiffre, 2) <= 19 Then 'entre 1 et 20
CtoL = CtoL & " " & U(Mid(Chiffre, 2))
Else
CtoL = CtoL & " " & D(Mid(Chiffre, 2, 1)) & " " & U(Mid(Chiffre, 3, 1))
If U(Mid(Chiffre, 2, 1)) <> "0" Then
'CtoL = Replace(CtoL, " ", "-")
End If
End If
Case Else
End Select
ici:
End If
End Function
Public Function Conversion_nombre_lettres(nombre As String) As String
On Error GoTo ici
U(1) = "un"
U(2) = "deux"
U(3) = "trois"
U(4) = "quatre"
U(5) = "cinq"
U(6) = "six"
U(7) = "sept"
U(8) = "huit"
U(9) = "neuf"
U(10) = "dix"
U(11) = "onze"
U(12) = "douze"
U(13) = "treise"
U(14) = "quatorze"
U(15) = "quinze"
U(16) = "seize"
U(17) = "dix-sept"
U(18) = "dix-huit"
U(19) = "dix-neuf"
D(2) = "vingt"
D(3) = "trente"
D(4) = "quarante"
D(5) = "cinquante"
D(6) = "soixante"
D(7) = "soixante-dix"
D(8) = "quatre-vingt"
D(9) = "quatre-vingt-dix"
D(10) = "cent"
If Not IsNumeric(nombre) Then Exit Function
'text2= & text2
Dim Tmp As String
Dim C As String
Dim M As String
Dim Millions As String
Dim i As Integer
Tmp = Replace(nombre, " ", "")
For i = 1 To 9 - Len(nombre)
Tmp = "0" & Tmp
Next
If Len(Tmp) >= 1 And Len(Tmp) <= 3 Then
C = Tmp
ElseIf Len(Tmp) >= 4 And Len(Tmp) <= 6 Then
C = Mid(Tmp, Len(Tmp) - 2)
Tmp = Mid(Tmp, 1, Len(Tmp) - 3)
M = Tmp
Else
C = Mid(Tmp, Len(Tmp) - 2)
M = Mid(Tmp, Len(Tmp) - 5, 3)
Tmp = Mid(Tmp, 1, Len(Tmp) - 6)
Millions = Tmp
End If
ici:
Tmp = "" 'pour ne pas déclarer plusieurs variables
If CInt(Millions) <> 0 Then Tmp = CtoL(CInt(Millions)) & " million"
If CInt(M) <> 0 Then Tmp = Tmp & " " & CtoL(CInt(M)) & IIf(CInt(M) <> 0, " mille", "")
If CInt(C) <> 0 Then Tmp = Tmp & " " & CtoL(CInt(C))
Conversion_nombre_lettres = Replace(Tmp, " ", " ")
Conversion_nombre_lettres = Trim(Conversion_nombre_lettres)
End Function |
Partager