1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 32, 96 To 105
Select Case Len(Text1.Text)
Case 3, 6, 9, 12
If KeyCode <> 32 Then
Dim KeyEnCour As String, Pos As Integer
Pos = Len(Text1.Text) - 1
KeyEnCour = Right(Text1.Text, 1)
Text1.Text = Left(Text1.Text, Pos) & " " & KeyEnCour
Text1.SelStart = Len(Text1.Text)
End If
Case Is > 12
Text1.Text = Left(Text1.Text, 14)
Text1.SelStart = Len(Text1)
End Select
Case 8, 37, 39, 46
Case Else
Text1.Text = Replace(Text1.Text, Chr(KeyCode), "", , , vbTextCompare)
Text1.SelStart = Len(Text1)
End Select
End Sub
Private Sub Text1_LostFocus()
'verification en sortie du textbox
Dim T As Integer, StrText As String
If Len(Text1.Text) = 10 Then
'cas d'un copier/coller de style: 1234567890
For T = 1 To 10 Step 2
StrText = StrText & Mid(Text1.Text, T, 2) & " "
Next T
Text1.Text = RTrim(StrText)
End If
For T = 1 To Len(Text1.Text)
Select Case T
Case 3, 6, 9, 12
If Mid(Text1.Text, T, 1) <> " " Then
MsgBox "votre entrée n'est pas valide"
Exit For
End If
Case Else
If Mid(Text1.Text, T, 1) = " " Then
MsgBox "votre entrée n'est pas valide"
Exit For
End If
End Select
Next T
End Sub |
Partager