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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| Public Sub teste_date(ByRef t As MSForms.TextBox, ByRef cod As MSForms.ReturnInteger, ByVal flt As String, scl As Boolean)
Dim ici As Byte, sp As String, cr As String, drf As String, dtt As String, siecle As Boolean
sp = Left(Replace(flt, "#", ""), 1)
drf = "31" & sp & "12" & sp & "2000" 'ne touche jamais rien à cette chaine
With t
ici = .SelStart
If cod = 46 And .SelText = Mid(.Text, ici + 1) Then
.Text = Left(.Text, ici)
If Len(.Text) = 2 Or Len(.Text) = 5 Then .Text = Left(.Text, Len(.Text) - 1)
cod = 0: Exit Sub
End If
If ici < Len(.Text) Then .SelStart = Len(.Text): cod = 0: Exit Sub
If cod = 8 Then
If ici = 3 Or ici = 6 Then .Text = Left(.Text, Len(.Text) - 1)
Exit Sub
End If
If cod = 37 And ici = 0 Then
If IsDate(.Tag) Then .Text = .Tag: cod = 0: Exit Sub
End If
If cod > 95 Then cr = Chr(cod - 48)
If ici = 3 Then Mid(drf, 1, 5) = IIf(cr = "0", "00" & sp & "01", "00" & sp & "02")
dtt = .Text & cr & Mid(drf, ici + 2)
If cod = 32 Then
If ici = 0 Or ici = 3 Or ici = 6 Or ici = 8 Then
Dim voir As String
voir = .Text & Mid(Format(Date, "dd" & sp & "mm" & sp & "yyyy"), ici + 1)
If IsDate(voir) Then .Text = voir
End If
cod = 0: Exit Sub
End If
If ici <> 8 Then
If Not IsDate(dtt) Or Not dtt Like flt Then cod = 0: Exit Sub
Else
If Not IsNumeric(cr) Then cod = 0: Exit Sub
End If
Select Case ici
Case 1, 4
If ici = 4 And Val(Mid(.Text, ici, 1) & cr) > 12 Then cod = 0: Exit Sub
If ici = 4 And scl Then
.Text = Left(dtt, Len(.Text & cr)) & sp & Int(Year(Date) / 100): cod = 0
Else
.Text = Left(dtt, Len(.Text & cr)) & sp: cod = 0
End If
Case 3
If cr > "1" Then cod = 0
End Select
End With
Application.CutCopyMode = True
End Sub
Public Sub alarme(f As UserForm, t As MSForms.TextBox, ByRef c As MSForms.ReturnBoolean)
Dim debut As Double, Msg_date As String
If t.Text <> "" And Len(t.Text) < 10 Then
c = True
With f.Msg_date
.Move t.Left - 20, t.Top - 10, t.Width + 40, 60
.ZOrder
.Font.Name = "MS Sans Serif"
.Font.Bold = True
.Font.Size = 9
.Caption = "la date doit être sous la forme jj/mm/aaaa avec un millésime sur 4 chiffres)"
.BackColor = vbYellow
.ForeColor = vbRed
.TextAlign = fmTextAlignCenter
.Visible = True
debut = Timer
Do While Timer < debut + 4
DoEvents
Loop
.Visible = False
End With
Else
If t.Text <> "" Then t.Tag = t.Text
End If
End Sub |
Partager