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
| Option Explicit
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim filtre As String, toto As String, I As Integer
Dim ou As Integer, titi As String, pos As Integer, entier As Long, deci As String
entier = Val(Text1.Text)
pos = InStr(Text1.Text, ",")
If pos > 0 Then
deci = Mid(Text1.Text, pos + 1)
Else
deci = "00"
End If
If KeyAscii = 8 Then
Text1.Text = ""
Exit Sub
End If
If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0: Exit Sub
toto = Chr(KeyAscii)
filtre = "# "
ou = Text1.SelStart
KeyAscii = 0
For I = 1 To 6
filtre = filtre & String(3, "##") & " "
Next
If ou < InStr(Text1.Text, ",") Or Text1.Text = "" Then
Text1.Text = Trim(Format(entier & toto, filtre)) & "," & deci
If Text1.Text <> "" Then Text1.SelStart = InStr(Text1.Text, ",") - 1
Else
titi = Text1.Text
If ou < Len(Text1.Text) Then Mid(titi, ou + 1, 1) = toto
Text1.Text = titi
Text1.SelStart = ou + 1
End If
End Sub |