Hello Forum
Hello tout le monde
Gentelmans ..
Je suis tres ravi de vous rejoindre dans ce best forum .. j'etais depuis deux ans avec VB6 ..
Mon premier pas et mon premier sujet dans VB NET .. si vous pouvez m'aider a finir ce cauchemar .. mille fois merci d'avance
Pour transformer les chiffres dans TextBox 1 en lettre dans TextBox2 ..il faut que je click sur Button 1
Tous ce que veux .. c'est eviter ce Button1 ..
Dès que je tape un chiffre dans TextBox1 s'affichera automatiquement l'ecriture dans TextBox2 sans que je click sur Button1
Voila mon code qui fonctionne tres tres bien ..
Module1 :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
Module Module1
    Public Pays As Byte
    Dim Decim As String, Stade As Integer
    Dim strResultat(6) As String
    Dim Reste As Single
    Dim StrReste As String
    Dim Devize As String
    Public Unite(19) As String
    Public Monnaie(7) As String
    Public Dixaines(9) As String
    Dim ValNb(6) As Double
    Dim mStrTemp As String
    Public Sep As String
    Function EnTexte(ByVal Chiffre As Double, Optional ByVal Langue As Byte = 0, Optional ByVal Devise As Byte = 0, Optional ByVal Decimale As Byte = 0) As String
        Dim i As Integer, txt As String
        Dim strTemp As String
        Dim Nombre As String, TB()
        If Chiffre = 0 Then EnTexte = "Zéro" : Exit Function
        Nombre = CStr(Chiffre) : strTemp = ""
        If Decimale = 0 Or Int(Chiffre) = Chiffre Then
            Nombre = Arrondi(Nombre, 0)
            Reste = 0
            If Int(Chiffre) = 0 And Reste = 0 Then EnTexte = "Zéro" : Exit Function
        Else
            TB = Split(CStr(Chiffre), Sep)
            Reste = TB(1) / 10 ^ Len(TB(1)) 'pour 2 décimales
            StrReste = TB(1) 'si pas de devise, met toutes les décimales
            If Chiffre < 1 Then
                strTemp = "Zéro "
                GoTo PasUnite
            End If
            Nombre = Int(Chiffre)
        End If
        Pays = Langue
        If Unite(1) = "" Then InitVar()
        InitPays()
reco:
        If Len(Nombre) / 3 <> Int(Len(Nombre) / 3) Then
            Nombre = "0" & Nombre
            GoTo reco
        End If
        Stade = (Len(Nombre) / 3)
        For i = 0 To Stade - 1
            txt = Mid(Nombre, (i * 3) + 1, 3)
            ValNb(i) = Val(txt)
            strResultat(i) = Centaine(txt)
        Next i
        i = 0
        If Stade > 4 Then 'Billiard
            If strResultat(i) <> "" Then
                strTemp = VoirRegle(strResultat(i)) & IIf(ValNb(i) = 1, "Billiard ", "Billiards ")
            End If
            i = i + 1
        End If
        If Stade > 3 Then 'Milliard
            If strResultat(i) <> "" Then
                strTemp = strTemp & VoirRegle(strResultat(i)) & IIf(ValNb(i) = 1, "Milliard ", "Milliards ")
            End If
            i = i + 1
        End If
        If Stade > 2 Then 'Million
            If strResultat(i) <> "" Then
                strTemp = strTemp & VoirRegle(strResultat(i)) & IIf(ValNb(i) = 1, "Million ", "Millions ")
            End If
            i = i + 1
        End If
        If Stade > 1 Then 'millier
            If strResultat(i) <> "" Then
                If strResultat(i) = "un " Then
                    strTemp = strTemp & "Mille "
                Else
                    strTemp = strTemp & VoirRegle(strResultat(i)) & "Mille "
                End If
            End If
            i = i + 1
        End If
        If Stade > 0 Then 'les unités
            If strResultat(i) <> "" Then
                If strTemp <> "" And ValNb(i) < 100 And (Right(strResultat(i), 3) <> "un " Or Len(strResultat(i)) = 3) Then
                    TB = Split(strTemp, " ")
 
                    Select Case TB(UBound(TB) - 1)
                        Case "Million", "Millions", "Milliard", "Milliards", "Billiard", "Billiards"
                            strTemp = strTemp & "et "
                    End Select
                End If
                strTemp = strTemp & VoirRegle(strResultat(i), False)
            End If
        End If
        TB = Split(strTemp, " ")
        Select Case TB(UBound(TB) - 1)
            Case "Million", "Millions", "Milliard", "Milliards", "Billiard", "Billiards"
                Select Case Devise
                    Case 1, 3 : strTemp = strTemp & "de "
                    Case 2 : strTemp = strTemp & "d'"
                End Select
        End Select
PasUnite:
        Select Case Devise
            Case Is > 0 : strTemp = strTemp & Monnaie(Devise) & IIf(Nombre = 1, " ", "s ")
        End Select
        If Reste <> 0 And Decimale = 1 Then
            If Devise = 0 Then
                strTemp = strTemp & "Virgule "
                'Appel pour les décimales en base 3
                strTemp = strTemp & AprVirgule(StrReste)
            Else
                strTemp = strTemp & " "
                Reste = Int(Reste * 1000) / 10
                ValNb(1) = Arrondi(Reste, 0)
 
                If ValNb(1) = 100 Then 'rectifie 100 centimes
                    strTemp = EnTexte(Arrondi(Chiffre, 0), Pays, Devise, 0)
                Else
                    txt = Right("00" & Trim(Str(ValNb(1))), 3)
                    txt = Centaine(txt) : txt = Trim(txt) & " "
                    strTemp = strTemp & VoirRegle(txt)
                    strTemp = strTemp & Monnaie(Devise + 4) & IIf(ValNb(1) = 1, "", "s")
                End If
            End If
        End If
        EnTexte = strTemp
    End Function
 
    Private Function AprVirgule(ByVal Nombre As String) As String
        Dim i As Integer, txt As String, strTemp As String, N(2)
        N(0) = "Millième" : N(1) = "Millionnième" : N(2) = "Milliardième"
reco:
        If Len(Nombre) / 3 <> Int(Len(Nombre) / 3) Then
            Nombre = Nombre & "0"
            GoTo reco
        End If
        Stade = (Len(Nombre) / 3) : strTemp = ""
        If Stade > 3 Then Stade = 3
        For i = 0 To Stade - 1
            txt = Mid(Nombre, (i * 3) + 1, 3)
            ValNb(i) = Val(txt)
            strResultat(i) = Centaine(txt)
        Next i
        For i = 0 To Stade - 1
            If strResultat(i) <> "" Then
                strTemp = strTemp & VoirRegle(strResultat(i)) & N(i) & IIf(ValNb(i) > 1, "s ", " ")
            End If
        Next i
        AprVirgule = strTemp
    End Function
 
    Private Function Centaine(ByVal Nombre As String) As String
        Dim i As Integer, e(3) As Integer, a As String
        Dim strBuff As String
        For i = 3 To 1 Step -1
            e(i) = Val(Mid(Nombre, i, 1))
        Next i
        e(0) = Val(Right(Nombre, 2))
 
        If e(3) = 1 Then
            If Pays = 0 Then
                If e(2) <= 7 Then strBuff = "et un " Else strBuff = Unite(e(3))
            Else
                If e(2) <> 8 Then strBuff = "et un " Else strBuff = Unite(e(3))
            End If
        Else
            strBuff = Unite(e(3))
        End If
        If e(0) < 20 Then
            strBuff = Unite(e(0))
        ElseIf e(0) < 70 Or (e(0) > 79 And e(0) < 90) Or Pays <> 0 Then
            If e(3) > 0 And Left(strBuff, 2) <> "et" Then
                strBuff = Trim(Dixaines(e(2))) & "-" & LTrim(strBuff)
            ElseIf strBuff <> "" Then
                strBuff = Dixaines(e(2)) & strBuff
            Else
                strBuff = Dixaines(e(2))
            End If
        Else
            If e(0) > 89 Then i = 80 Else i = 60
            If e(3) = 1 And e(2) = 7 Then
                strBuff = RTrim(Dixaines(e(2) - 1)) & " " & "et onze "
            Else
                strBuff = RTrim(Dixaines(e(2) - 1)) & "-" & Unite(e(0) - i)
            End If
        End If
 
        'Centaine
        If e(1) = 1 Then
            strBuff = "cent " & strBuff
        ElseIf e(1) >= 1 Then
            If e(0) = 0 Then a = "cents " Else a = "cent "
            strBuff = Unite(e(1)) & "cent " & strBuff
        End If
        Centaine = strBuff
    End Function
 
    Private Function Arrondi(ByVal Nombre, ByVal Decimales)
        Arrondi = Int(Nombre * 10 ^ Decimales + 1 / 2) / 10 ^ Decimales
    End Function
 
    Private Function VoirRegle(ByVal V As String, Optional ByVal Stde As Boolean = True) As String
        If Right(V, 6) = "vingt " Then
            If Stde Then
                VoirRegle = V
            ElseIf Len(V) > 6 Then
                VoirRegle = RTrim(V) & "s "
            Else
                VoirRegle = V
            End If
        ElseIf Right(V, 4) = "ent " Then
            If Stde Then
                VoirRegle = V
            ElseIf Len(V) > 5 Then
                VoirRegle = RTrim(V) & "s "
            Else
                VoirRegle = V
            End If
        Else
            VoirRegle = V
        End If
    End Function
 
End Module
Module 2 :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Module Module2
    Public Sub InitVar()
        Unite(0) = "" : Unite(1) = "un " : Unite(2) = "deux " : Unite(3) = "trois " : Unite(4) = "quatre "
        Unite(5) = "cinq " : Unite(6) = "six " : Unite(7) = "sept " : Unite(8) = "huit " : Unite(9) = "neuf "
        Unite(10) = "dix " : Unite(11) = "onze " : Unite(12) = "douze " : Unite(13) = "treize " : Unite(14) = "quatorze "
        Unite(15) = "quinze " : Unite(16) = "seize " : Unite(17) = "dix-sept " : Unite(18) = "dix-huit " : Unite(19) = "dix-neuf "
 
        Dixaines(2) = "vingt " : Dixaines(3) = "trente " : Dixaines(4) = "quarante " : Dixaines(5) = "cinquante " : Dixaines(6) = "soixante "
 
        Monnaie(0) = "" : Monnaie(1) = "Dollar" : Monnaie(2) = "Euro" : Monnaie(3) = "Franc"
        Monnaie(4) = "" : Monnaie(5) = "Cent" : Monnaie(6) = "Centime" : Monnaie(7) = "Centime"
    End Sub
 
    Sub InitPays()
        Select Case Pays
            Case 0 'France
                Dixaines(7) = "soixante-dix "
                Dixaines(8) = "quatre-vingt "
                Dixaines(9) = "quatre-vingt-dix "
            Case 1 'Belge
                Dixaines(7) = "septante "
                Dixaines(8) = "quatre-vingt "
                Dixaines(9) = "nonante "
            Case 2 'suisse
                Dixaines(7) = "septante "
                Dixaines(8) = "huitante "
                Dixaines(9) = "nonante "
        End Select
    End Sub
 
End Module
Form 1:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
'Imports System.EventArgs
Public Class Form1
    Dim Monnaie As Byte
    Dim Py As Byte
    Dim DCI As Byte
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Sep = Application.CurrentCulture.NumberFormat.NumberDecimalSeparator
        Py = 0 : Monnaie = 2 : DCI = 1
        Envoyer()
    End Sub
    Sub Envoyer()
        Dim DT As String
        'Pour adapter à la configuration du PC hôte.
        DT = Replace(TextBox1.Text, ".", Sep)
        DT = Replace(DT, ",", Sep)
 
        TextBox2.Text = EnTexte(CDbl(DT), Py, Monnaie, DCI)
        On Error Resume Next
        TextBox1.SelectionStart = 0 'Len(Data.Text)
        TextBox1.SelectionLength = Len(TextBox1.Text)
        TextBox1.Focus()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Envoyer()
    End Sub
    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = 13 Then Envoyer()
    End Sub
End Class
Cordialement
MADA BLACK