Seulement des chiffres dans le champ Text

pioug43 Messages postés 32 Date d'inscription lundi 23 décembre 2002 Statut Membre Dernière intervention 3 novembre 2006 - 24 mars 2003 à 09:24
albator7k Messages postés 9 Date d'inscription lundi 24 mars 2003 Statut Membre Dernière intervention 27 mars 2003 - 24 mars 2003 à 10:02
Je voudrais connaitre la propriete ou la maniere de faire pour que l'utilisateur ne puisse rentrer que des chiffres dans une text box. Merci

2 réponses

fredlynx Messages postés 662 Date d'inscription mercredi 16 janvier 2002 Statut Modérateur Dernière intervention 16 octobre 2010 3
24 mars 2003 à 09:32
Version code :
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub 'Backspace
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub

Version API :
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const ES_NUMBER = &H2000&
Private Const GWL_STYLE = (-16)

SetWindowLong Text1.hWnd, GWL_STYLE, GetWindowLong(Text1.hWnd, GWL_STYLE) Or ES_NUMBER
Text1.Refresh

<center>http://www.fredlynx.com
</center>
0
albator7k Messages postés 9 Date d'inscription lundi 24 mars 2003 Statut Membre Dernière intervention 27 mars 2003
24 mars 2003 à 10:02
mets ça

Private Sub Combo4_KeyPress(KeyAscii As Integer)

If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then KeyAscii = 0
End Sub
0
Rejoignez-nous