cs_CanisLupus
Messages postés3757Date d'inscriptionmardi 23 septembre 2003StatutMembreDernière intervention13 mars 200621 7 janv. 2005 à 17:20
Oups, je suis allé trop vite, il y a un bug. Donc dernière version :
Private Sub Text1_KeyPress(KeyAscii As Integer)
' on élimine le 0 si c'est le 1er chiffre saisi If Len(Text1.Text) 0 And KeyAscii 48 Then
KeyAscii = 0
Exit Sub
End If
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
' test si c'est un chiffre entré (clavier ou numpad)
If Len(Text1.Text) > 0 And ((KeyCode >= 48 And KeyCode <= 57) Or (KeyCode >= 96 And KeyCode <= 105)) Then
Select Case Len(Text1.Text)
Case 1 ' s'il y à un seul chiffre saisi
Text1.Text = Text1.Text / 100
Case Is > 1 ' s 'il y a déjà au moins 2 chiffres saisis
Text1.Text = Format$(Text1.Text * 10, "0.00") ' pour garder les 0 de droite
End Select
Text1.SelStart = Len(Text1.Text)
End If
End Sub
cs_CanisLupus
Messages postés3757Date d'inscriptionmardi 23 septembre 2003StatutMembreDernière intervention13 mars 200621 7 janv. 2005 à 17:00
Salut,
A la place d'un maskedit, tu peux utiliser une textbox avec ça dedans :
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
' test si c'est un chiffre entré (clavier ou numpad)
If (KeyCode >= vbKey0 And KeyCode <= vbKey9) Or (KeyCode >= vbKeyNumpad0 And KeyCode <= vbKeyNumpad9) Then
' si la textbox est vide ou à 0 If Len(Text1.Text) 1 Or CDbl(Text1.Text) 0 Then
Text1.Text = Text1.Text / 100
Else: s 'il y a déjà au moins un chiffre saisi
Text1.Text = Text1.Text * 10
End If
Text1.SelStart = Len(Text1.Text)
End If
End Sub