- 'Dessinez une TextBox, nommez-la ZT, puis mettez sa propriété MaxLength à 10
- 'Puis dans le code, collez ces 2 courtes procédures :
-
-
- Private Sub ZT_Change()
- Dim p As Integer
- p = ZT.SelStart
- If Len(ZT.Text) = 3 Then
- If Mid$(ZT.Text, 3, 1) <> "/" Then
- If Mid$(ZT.Text, 2, 1) = "/" Then ZT.Text = "0" & ZT.Text Else ZT.Text = Left$(ZT.Text, 2) & "/" & Right$(ZT.Text, 1)
- p = p + 1
- End If
- If Val(Left$(ZT.Text, 2)) > 31 Then ZT.Text = "31" & Mid$(ZT.Text, 3, Len(ZT.Text) - 2)
- End If
- If Len(ZT.Text) = 6 Then
- If Mid$(ZT.Text, 6, 1) <> "/" Then
- If Mid$(ZT.Text, 5, 1) = "/" Then ZT.Text = Left$(ZT.Text, 3) & "0" & Right$(ZT.Text, 3) Else ZT.Text = Left$(ZT.Text, 5) & "/" & Right$(ZT.Text, 1)
- p = p + 1
- End If
- If Val(Mid$(ZT.Text, 4, 2)) > 12 Then ZT.Text = Left$(ZT.Text, 3) & "12" & Mid$(ZT.Text, 6, Len(ZT.Text) - 5)
- End If
- ZT.SelStart = p
- End Sub
-
- Private Sub ZT_KeyPress(KeyAscii As Integer)
- If KeyAscii = 47 Then
- Select Case Len(ZT.Text)
- Case 1, 2, 4, 5
- Case Else
- KeyAscii = 0
- End Select
- Else
- If InStr(1, "0123456789/" & Chr$(vbKeyBack), Chr$(KeyAscii)) = 0 Then KeyAscii = 0
- End If
- End Sub
'Dessinez une TextBox, nommez-la ZT, puis mettez sa propriété MaxLength à 10
'Puis dans le code, collez ces 2 courtes procédures :
Private Sub ZT_Change()
Dim p As Integer
p = ZT.SelStart
If Len(ZT.Text) = 3 Then
If Mid$(ZT.Text, 3, 1) <> "/" Then
If Mid$(ZT.Text, 2, 1) = "/" Then ZT.Text = "0" & ZT.Text Else ZT.Text = Left$(ZT.Text, 2) & "/" & Right$(ZT.Text, 1)
p = p + 1
End If
If Val(Left$(ZT.Text, 2)) > 31 Then ZT.Text = "31" & Mid$(ZT.Text, 3, Len(ZT.Text) - 2)
End If
If Len(ZT.Text) = 6 Then
If Mid$(ZT.Text, 6, 1) <> "/" Then
If Mid$(ZT.Text, 5, 1) = "/" Then ZT.Text = Left$(ZT.Text, 3) & "0" & Right$(ZT.Text, 3) Else ZT.Text = Left$(ZT.Text, 5) & "/" & Right$(ZT.Text, 1)
p = p + 1
End If
If Val(Mid$(ZT.Text, 4, 2)) > 12 Then ZT.Text = Left$(ZT.Text, 3) & "12" & Mid$(ZT.Text, 6, Len(ZT.Text) - 5)
End If
ZT.SelStart = p
End Sub
Private Sub ZT_KeyPress(KeyAscii As Integer)
If KeyAscii = 47 Then
Select Case Len(ZT.Text)
Case 1, 2, 4, 5
Case Else
KeyAscii = 0
End Select
Else
If InStr(1, "0123456789/" & Chr$(vbKeyBack), Chr$(KeyAscii)) = 0 Then KeyAscii = 0
End If
End Sub