OVH Cloud OVH Cloud

Date dans TextBox

4 réponses
Avatar
David
Bonsoir à tous

Cette proc. ci-dessous me pose un problème car si l'on saisie 35 par erreur
cela m'indique une erreur 13.
comment m'informer qu'il y a une erreur
Merci de votre aide si précieuse

David

Private Sub TextBox5_AfterUpdate()
Select Case Len(TextBox5)
Case Is = 2
TextBox5 = Format(CDate(CLng(TextBox5) & "/" & Month(Date) & "/" &
Year(Date)), "dd/mm/yyyy")
Case Is = 4
TextBox5 = Format(CDate(CLng(Left(TextBox5, 2)) & "/" & CLng(Right(TextBox5,
2)) & "/" & Year(Date)), "dd/mm/yyyy")
Case Is = 6
TextBox5 = Format(CDate(CLng(Left(TextBox5, 2)) & "/" & CLng(Mid(TextBox5,
3, 2)) & "/" & CLng(Right(TextBox5, 2))), "dd/mm/yyyy")
Case Else: TextBox5 = "": End Select
End Sub

4 réponses

Avatar
Ilan
Bonsoir,

essaie ceci. J'ai tente de prevoir les cas ou la longueur de chaine est
impaire.
Exemple:
1 => 01/10/2004
112 => 01/12/2004
10105 => 01/01/2005

Sub TextBox5_AfterUpdate()
Dim jour, mois, annee
jour = Day(Date)
mois = month(Date)
annee = Year(Date)
Select Case Len(TextBox5.Value)
Case Is >= 5
jour = CInt(Left(TextBox5.Value, Len(TextBox5.Value) - 4))
mois = CInt(Mid(TextBox5.Value, Len(TextBox5.Value) - 3, 2))
annee = CInt(Right(TextBox5.Value, 2))
Case Is <= 4
jour = CInt(Left(TextBox5.Value, Len(TextBox5.Value) - 2))
mois = CInt(Right(TextBox5.Value, 2))
Case Is <= 2
jour = CInt(TextBox5.Value)
End Select
TextBox5.Value = CDate(jour & "/" & mois & "/" & annee)
End Sub



Bonsoir à tous

Cette proc. ci-dessous me pose un problème car si l'on saisie 35 par erreur
cela m'indique une erreur 13.
comment m'informer qu'il y a une erreur
Merci de votre aide si précieuse

David

Private Sub TextBox5_AfterUpdate()
Select Case Len(TextBox5)
Case Is = 2
TextBox5 = Format(CDate(CLng(TextBox5) & "/" & Month(Date) & "/" &
Year(Date)), "dd/mm/yyyy")
Case Is = 4
TextBox5 = Format(CDate(CLng(Left(TextBox5, 2)) & "/" & CLng(Right(TextBox5,
2)) & "/" & Year(Date)), "dd/mm/yyyy")
Case Is = 6
TextBox5 = Format(CDate(CLng(Left(TextBox5, 2)) & "/" & CLng(Mid(TextBox5,
3, 2)) & "/" & CLng(Right(TextBox5, 2))), "dd/mm/yyyy")
Case Else: TextBox5 = "": End Select
End Sub





Avatar
Ilan
Oops! J'ai oublie l'essentiel dans le post precedent. Desole

En fait, je recupere le Dernier jour du mois. Si l'utilisateur entre
une valeur plus grande alors jour= dernier jour.

Sub TextBox5_AfterUpdate()
Dim jour as integer, mois as integer, annee as integer, JourMax as integer
jour = Day(Date)
mois = month(Date)
annee = Year(Date)
Jourmax1
Select Case Len(TextBox5.Value)
Case Is = 5, 6
jour = CInt(Left(TextBox5.Value, Len(TextBox5.Value) - 4))
mois = CInt(Mid(TextBox5.Value, Len(TextBox5.Value) - 3, 2))
annee = CInt(Right(TextBox5.Value, 2))
Case Is = 3, 4
jour = CInt(Left(TextBox5.Value, Len(TextBox5.Value) - 2))
mois = CInt(Right(TextBox5.Value, 2))
Case Is = 1, 2
jour = CInt(TextBox5.Value)
End Select
if mois<>12 then JourMax = Day(DateAdd("d", -1, "01/" & mois+1 & "/" & annee))
If jour > JourMax Then jour = JourMax
TextBox5.Value = CDate(jour & "/" & mois & "/" & annee)
End Sub



Bonsoir à tous

Cette proc. ci-dessous me pose un problème car si l'on saisie 35 par erreur
cela m'indique une erreur 13.
comment m'informer qu'il y a une erreur
Merci de votre aide si précieuse

David

Private Sub TextBox5_AfterUpdate()
Select Case Len(TextBox5)
Case Is = 2
TextBox5 = Format(CDate(CLng(TextBox5) & "/" & Month(Date) & "/" &
Year(Date)), "dd/mm/yyyy")
Case Is = 4
TextBox5 = Format(CDate(CLng(Left(TextBox5, 2)) & "/" & CLng(Right(TextBox5,
2)) & "/" & Year(Date)), "dd/mm/yyyy")
Case Is = 6
TextBox5 = Format(CDate(CLng(Left(TextBox5, 2)) & "/" & CLng(Mid(TextBox5,
3, 2)) & "/" & CLng(Right(TextBox5, 2))), "dd/mm/yyyy")
Case Else: TextBox5 = "": End Select
End Sub





Avatar
David
Re

Une nouvelle fois Ilan, c'est impec

Mille merci
Avatar
David
Re

Après essai, il peut quand même y avoir une erreur en faisant qu'un 0
(zéro)

Désolé

Bonne journée

David