Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I NEED GOOD FUNCTIONING EXAMPLES OF TIME SUBTRACTION!

Status
Not open for further replies.

dandyboy

Programmer
Jan 9, 2002
24
US
I have tried various ways of approaching how to subtract two times from each other but I always end up with the value '1'.
Could anyone supply me with their entire program or the related parts to a V-B 6.0 program doing the subtraction between 2 times. I keep adding new code and I am unsure of whether I've commented out the old.


*Private Sub cmdLostCall_Click()
''**********************************************************
*
'* Here I count the number of times the Lost Call is used
'* and I record the length of time of that particular call.
'***********************************************************
*
'*(TheDate = Format(Now, "short date")
'*rst!DateIn = TheDate
'* Call Later(TimeOut, Time)
'* If cmdLostCall.Enabled = True Then
'* LostCall_Cnt = LostCall_Cnt + 1
'* rst!LostCount = LostCall_Cnt
'* If cmdLostCall.Enabled = False Then
'* TimeOut = Time
'* rst!LostCallLength = (TimeOut) - (TimeIn)
'* End If

'* End If
Call CmdClear_Click
End Sub

Private Sub cmdExit_Click()
'***********************************************************
******
'* This Ends the Input Session.
'***********************************************************
******
End
End Sub
'***********************************************************
******
'* THE TIMER STARTS THE FIRST TIME A CHARACTER GETS TYPED
IN.
'***********************************************************
******

Private Sub EIN_No_KeyUp(KeyCode As Integer, Shift As
Integer)
If Len(EIN_No) = EIN_No.MaxLength Then
Phone_No.SetFocus

End If
TimeIn = Time
End Sub


Private Sub Name_Str_KeyDown(KeyCode As Integer, Shift As
Integer)
If KeyCode = 13 Then
Buisness_Str.SetFocus
'********************************************************
*********
'* THE TIMER STARTS THE FIRST TIME A CHARACTER GETS
TYPED IN.
'********************************************************
*********
End If
Form_Maximize
End Sub


Private Sub Phone_No_KeyDown(KeyCode As Integer, Shift As
Integer)
If KeyCode = 13 Then
Name_Str.SetFocus
'*******************************************************
**********
'* THE TIMER STARTS THE FIRST TIME A CHARACTER GETS
TYPED IN.
'********************************************************
*********
End If
Form_Maximize
End Sub




'*Private Sub Phone_No_KeyDown(KeyCode As Integer, Shift As
Integer)

'*If KeyCode = 13 Then
'* Name_Str.SetFocus
'*******************************************************
**********
'* THE TIMER STOPS THE FIRST TIME THE cmdLostCall
button is clicked.
'********************************************************
*********
Private Sub cmdLostCall_Click()
rst!EIN = txtEIN_No
rst!PhoneNumber = txtPhone_Num
rst!FirstName = txtname_first
rst!LastName = txtname_last
rst!BusinessType = txtBuisness
If OptSelfOnly.Value = True Then
rst!ReportingFor = "Self Only"
End If
If OptAnotherEmployer.Value = True Then
rst!ReportingFor = "Another Employer"
End If
If OptSandA.Value = True Then
rst!ReportingFor = "Self and Another
Employer"
End If
rst!PayrollSoftware = ChkPayroll
rst!SSAPostCard = ChkPostCard
If ChkSpeech.Value = 1 Then
rst!InformationSource = "Speech at Conference"
End If
If ChkArticle.Value = 1 Then
rst!InformationSource = "Magazine Article"
End If
If ChkEmployer.Value = 1 Then
rst!InformationSource = "Another
Employer"
End If
If chkOther.Value = 1 Then
rst!LostTime = Time
End If
TheDate = Format(Now, "short date")
rst!DateIn = TheDate
rst.Update
If cmdLostCall.Enabled = True Then
TimeOut = Time
txtLostTime = TimeOut - TimeIn
rst!LostCallLength = (TimeOut) - (TimeIn)
End If
Call CmdClear_Click
txtEIN_No.SetFocus

End Sub


************************************************************
************************************************************
************************************************************
HERE IS THE MODULE:

Option Explicit
Public Difference As String
Public TimeIn As Variant
Public TimeOut As Variant
Public TheDate As String
Public Mins As Long
Public Secs As Long

'**********************************************************
'* THIS MODULE GETS A TIMER STARTED.
'**********************************************************
Public Function Shorter(StartDate, EndDate) As String

Dim Days As Long
Dim Hours As Long
Dim Mins As Long
Dim Secs As Long

Days = DateDiff("d", StartDate, EndDate)
StartDate = DateAdd("d", Days, StartDate)
Hours = DateDiff("h", StartDate, EndDate)
StartDate = DateAdd("h", Hours, StartDate)
Mins = DateDiff("n", StartDate, EndDate)
StartDate = DateAdd("n", Mins, StartDate)
Secs = DateDiff("s", StartDate, EndDate)
Shorter = Hours & " Hrs " & Mins & " Mins " & Secs & "
Secs"
Difference = Shorter
End Function
 
Wnat datatype are you putting the result of your subtraction of two floating point values into?

Wil Mead
wmead@optonline.net

 
Public Function TimeDiff(StartTime As Date, EndTime As Date) As String
TimeDiff = ((EndTime - StartTime) \ 1) & "Days " & Format(EndTime - StartTime, "hh:mm:ss") 'Choose your own format...
End Function
 
oops - line in that function should actually read:

TimeDiff = Fix(EndTime - StartTime) & "Days " & Format(EndTime - StartTime, "hh:mm:ss")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top