Source / Exemple :
Placez deux zones de texte dont la propriété Name est text1 et text2 puis coller le code suivant
Dans le module de la forme.
Private Sub text1_KeyPress(KeyAscii As Integer)
Call controle(KeyAscii, text1)
If KeyAscii = 13 Then text2.SetFocus
End Sub
Private Sub text1_LostFocus()
Call afficher(text1)
End Sub
Private Sub text2_KeyPress(KeyAscii As Integer)
Call controle(KeyAscii, text2)
If KeyAscii = 13 Then text1.SetFocus
End Sub
Private Sub text2_LostFocus()
Call afficher(text2)
End Sub
Private Sub controle(KeyAscii As Integer, bbb As TextBox)
Dim MOT
Dim k as byte
Select Case KeyAscii
Case vbKey0 To vbKey9
Case vbKeyRight, vbKeyLeft, vbKeyReturn, vbKeyBack
Case Asc(","), Asc(".")
MOT = bbb.Text
For k = 1 To Len(MOT)
If Mid(MOT, k, 1) = "," Or Mid(MOT, k, 1) = "." Then KeyAscii = 0
Next
Case Else
KeyAscii = 0
MsgBox "tapez un chiffre entre 0 et 1 ", , "Erreur ou ommission"
End Select
End Sub
Private Sub afficher(bbb As TextBox)
Dim reponse As Variant
If bbb.Text = "" Or bbb.Text = "." Or bbb.Text = "," Then bbb.Text = 0
If CDbl(bbb.Text) > 1 Or CDbl(bbb.Text) < 0 Then
reponse = MsgBox("tapez un chiffre entre 0 et 1 ", vbOKOnly, "Erreur de saisi")
bbb.SetFocus
bbb.Text = ""
Else
bbb.Text = Format(CDbl(bbb.Text), "0.000")
If CDbl(bbb.Text) = 0 Then bbb.Text = 0
If CDbl(bbb.Text) = 1 Then bbb.Text = 1
End If
End Sub
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.