'************************************************************************
'Calcul automatique de la durée Arrêt Production
'************************************************************************
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim a, b, c As Variant
a = 0
b = 0
c = 0
If TextBox5 = "" Then
Else
a = Left(TextBox4, InStr(TextBox4, "h") - 1)
b = Left(TextBox5, InStr(TextBox5, "h") - 1)
If b > a Then
c = b - a
Else
c = (b + 24) - a
End If
If c < 10 Then
TextBox6 = "0" & c & "h00"
Else
TextBox6 = c & "h00"
End If
End If
End Sub
'************************************************************************
'Calcul automatique de la durée Arrêt Production
'************************************************************************
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim a, b, c As Variant
a = 0
b = 0
c = 0
If TextBox4 = "" Then
Else
a = Left(TextBox4, InStr(TextBox4, "h") - 1)
b = Left(TextBox5, InStr(TextBox5, "h") - 1)
If b > a Then
c = b - a
Else
c = (b + 24) - a
End If
If c < 10 Then
TextBox6 = "0" & c & "h00"
Else
TextBox6 = c & "h00"
End If
valtrase
Messages postés937Date d'inscriptionlundi 19 janvier 2004StatutMembreDernière intervention 9 mai 20223 9 déc. 2005 à 00:46
Lut,
C'est normal c'est toi qui demande de ne prendre que la partie gauche de "12h15"
a = Left(TextBox4, InStr(TextBox4, "h") - 1)
b = Left(TextBox5, InStr(TextBox5, "h") - 1)
Donc si l'on reprend ton code ......
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Date1 As Date: Dim Date2 As Date
If TextBox2 = "" Then
'MsgBox "La deuxième heure doit être entrée !!"
Else
Date1 = Replace(TextBox1, "h", ":")
Date2 = Replace(TextBox2, "h", ":")
If Date2 > Date1 Then
TextBox6 = CDate(Date2 - Date1)
Else
TextBox6 = CDate(Date1 - Date2)
End If
End If
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Date1 As Date: Dim Date2 As Date
If TextBox2 = "" Then
'MsgBox "La première heure doit être entrée !!"
Else
Date1 = Replace(TextBox1, "h", ":")
Date2 = Replace(TextBox2, "h", ":")
If Date2 > Date1 Then
TextBox6 = CDate(Date2 - Date1)
Else
TextBox6 = CDate(Date1 - Date2)
End If
End If
End Sub
Cordialement, Jean-Paul
______________________________________________________________________
le DateDiff te renvoi le nombre de minute entre les deux dates placee en parametre
le DateAdd te permet de convertir le nombre de minute en heures:minutes