Formatage maskedit

Résolu
mtlcyr Messages postés 5 Date d'inscription mercredi 26 mai 2004 Statut Membre Dernière intervention 10 février 2005 - 7 janv. 2005 à 15:58
cs_CanisLupus Messages postés 3757 Date d'inscription mardi 23 septembre 2003 Statut Membre Dernière intervention 13 mars 2006 - 7 janv. 2005 à 17:20
Salut tous le monde, si quelequ'un peux m'aider:

je voudrais que on maskerdit se formate automatiquement a chaque saisie d'une touche

en format :

si je tape 1 il doit me donner 0.01$

ensuite si je tape 2 il doit me donner 0.12$

ensuite si je tape 3 il doit me donner 1.23$

etc...



merci beaucoup de votre aide
mtl

3 réponses

cs_CanisLupus Messages postés 3757 Date d'inscription mardi 23 septembre 2003 Statut Membre Dernière intervention 13 mars 2006 21
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

Cordialement, CanisLupus
3
cs_CanisLupus Messages postés 3757 Date d'inscription mardi 23 septembre 2003 Statut Membre Dernière intervention 13 mars 2006 21
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

Cordialement, CanisLupus
0
mtlcyr Messages postés 5 Date d'inscription mercredi 26 mai 2004 Statut Membre Dernière intervention 10 février 2005
7 janv. 2005 à 17:12
Merci beaucoup de ta reponse rapide, je test

merci encore

mtl
0
Rejoignez-nous