- Private Sub Text1_KeyPress(KeyAscii As Integer)
- If KeyAscii = 13 Then
- ' On valide la saisie
- Else
- KeyAscii = SaisieNombre(Text1, KeyAscii, 3)
- End If
- End Sub
-
-
- ' Dans un module
-
- Public Function SaisieNombre(ZonedeSaisie As Control, KeyAscii As Integer, deci As Long)
- ' Contrôle la saisie d'un nombre à virgule
-
- If KeyAscii > 32 And KeyAscii < 126 Then
- If KeyAscii = 44 Or KeyAscii = 46 Then ' 44 => , 46=> .
- If InStr(ZonedeSaisie.Text, ".") = 0 Then
- KeyAscii = 46
- Else
- KeyAscii = 0
- End If
- Else
- If KeyAscii = 45 Then
- If InStr(ZonedeSaisie, Chr$(KeyAscii)) = 0 Then
- ZonedeSaisie = "-" + ZonedeSaisie 'Inverser le nombre , négatif , positif
- Else
- ZonedeSaisie = Right(ZonedeSaisie, Len(ZonedeSaisie) - 1)
- End If
- SendKeys "{END}"
- KeyAscii = 0
- Else
- If InStr("1234567890-", Chr$(KeyAscii)) = 0 Then
- KeyAscii = 0
- Else
- If InStr(ZonedeSaisie.Text, ".") > 0 And KeyAscii = 46 Then KeyAscii = 0 ' Si le point existe, alors on retourne 0
- End If
- End If
- End If
-
- If Left(Right(ZonedeSaisie, deci + 1), 1) = "." Then
- KeyAscii = 0
- End If
-
- Else
-
- If KeyAscii = 8 Then ' BackSpace
- Else
- KeyAscii = 0
- End If
- End If
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
' On valide la saisie
Else
KeyAscii = SaisieNombre(Text1, KeyAscii, 3)
End If
End Sub
' Dans un module
Public Function SaisieNombre(ZonedeSaisie As Control, KeyAscii As Integer, deci As Long)
' Contrôle la saisie d'un nombre à virgule
If KeyAscii > 32 And KeyAscii < 126 Then
If KeyAscii = 44 Or KeyAscii = 46 Then ' 44 => , 46=> .
If InStr(ZonedeSaisie.Text, ".") = 0 Then
KeyAscii = 46
Else
KeyAscii = 0
End If
Else
If KeyAscii = 45 Then
If InStr(ZonedeSaisie, Chr$(KeyAscii)) = 0 Then
ZonedeSaisie = "-" + ZonedeSaisie 'Inverser le nombre , négatif , positif
Else
ZonedeSaisie = Right(ZonedeSaisie, Len(ZonedeSaisie) - 1)
End If
SendKeys "{END}"
KeyAscii = 0
Else
If InStr("1234567890-", Chr$(KeyAscii)) = 0 Then
KeyAscii = 0
Else
If InStr(ZonedeSaisie.Text, ".") > 0 And KeyAscii = 46 Then KeyAscii = 0 ' Si le point existe, alors on retourne 0
End If
End If
End If
If Left(Right(ZonedeSaisie, deci + 1), 1) = "." Then
KeyAscii = 0
End If
Else
If KeyAscii = 8 Then ' BackSpace
Else
KeyAscii = 0
End If
End If