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
| Option Compare Database
Dim Unités() As String
Dim Dizaines() As String
Private Sub Somme_chiffre_AfterUpdate()
Me.Somme_lettre.Value = ConvertirEnLettresNombre(Me.Somme_chiffre.Value)
End Sub
Function ConvertirEnLettresNombre(ByVal Nombre As Double) As String
InitialiserTableaux
Dim Résultat As String
Dim PartieEntière As Long
Dim PartieDécimale As Long
' Séparer la partie entière et la partie décimale
PartieEntière = Fix(Nombre)
PartieDécimale = Round((Nombre - PartieEntière) * 100)
' Convertir la partie entière en lettres
If PartieEntière > 999 Then
ConvertirEnLettresNombre = "Nombre trop grand pour être converti."
Exit Function
ElseIf PartieEntière = 0 Then
ConvertirEnLettresNombre = "zéro"
Exit Function
ElseIf PartieEntière > 99 Then
Résultat = ConvertirCentaines(PartieEntière \ 100)
PartieEntière = PartieEntière Mod 100
End If
If PartieEntière > 19 Then
Dim dizainePartieEntiere As Long
dizainePartieEntiere = PartieEntière \ 10
If PartieEntière Mod 10 = 1 Or PartieEntière Mod 10 = 11 Then
Résultat = Résultat & " " & Dizaines(dizainePartieEntiere) & "-et"
Else
Résultat = Résultat & " " & Dizaines(dizainePartieEntiere)
If PartieEntière Mod 10 <> 0 Then
Résultat = Résultat & "-" & Unités(PartieEntière Mod 10)
End If
End If
ElseIf PartieEntière > 0 Then
Résultat = Résultat & " " & Unités(PartieEntière)
End If
' Ajouter la partie décimale si elle existe
If PartieDécimale > 0 Then
Résultat = Résultat & " et " & ConvertirEnLettresNombre(PartieDécimale) & " centimes"
End If
ConvertirEnLettresNombre = Résultat
End Function
Function ConvertirCentaines(ByVal Nombre As Long) As String
Dim Resultat As String
If Nombre = 1 Then
Resultat = "cent"
ElseIf Nombre >= 2 And Nombre <= 9 Then
Resultat = Unités(Nombre) & " cents"
Else
Resultat = ""
End If
ConvertirCentaines = Resultat
End Function
Private Sub InitialiserTableaux()
Unités = Array("", "un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf", "dix", "onze", "douze", "treize", "quatorze", "quinze", "seize", "dix-sept", "dix-huit", "dix-neuf")
Dizaines = Array("", "", "vingt", "trente", "quarante", "cinquante", "soixante", "soixante-dix", "quatre-vingt", "quatre-vingt-dix")
End Sub |
Partager