|
-
Nov 27th, 2000, 10:33 AM
#1
Thread Starter
Addicted Member
I want to be able to subtract(endtime-starttime) and have (repairtime+setuptime+pmtime) equal the value from endtime-starttime. EndTime and Starttime are 8:00(military time) and repairtime, setuptime, pmtime are 60(integers).
This is the code I have come up with so far:
MyTime = (Val(txtEndTime) - Val(txtStartTime))
MyWorkTime = (Val(txtRepairTime) + Val(txtSetupTime) + Val(txtPMTime))
If Not MyTime = MyWorkTime Then
MsgBox "The hours or minutes do not equal the total hour and minutes from Start Time and End Time."
txtRepairTime.SetFocus
Exit Sub
End If
The problem is when the correct time is put in the msgbox still comes up, but if the time is correct then I want the record to be added. And when the time is incorrect I don't want the record to be added. See the only way to find out if the time is correct the user will press on the add button and then the msgbox comes up only when the time is incorrect. But I don't think the times are even being compared. Can anyone help me with this problem?
Thanks jeffro
-
Nov 27th, 2000, 10:52 AM
#2
Lively Member
could u give the data of the textfields
-
Nov 27th, 2000, 11:05 AM
#3
Thread Starter
Addicted Member
StartTime = 8:00
EndTime = 9:00
RepairTime = 40
SetupTime = 20
PMTime = 0
Those are some examples.
jeffro
-
Nov 27th, 2000, 11:38 AM
#4
Lively Member
instead of val convert it time an try Cdate(txtEndTime,hh:mm) etc.. may u will get the solution
-
Nov 27th, 2000, 11:48 AM
#5
Thread Starter
Addicted Member
I tried the example you gave me but I get an error and it highlights the ,.
Then I tried just cdate(txtendtime)- cdate(txtstarttime), but that didn't work either.
any other suggestions?
thanks jeffro
-
Nov 27th, 2000, 12:11 PM
#6
Fanatic Member
Jeffro,
You might try the DateDiff function, similar to the following.
Code:
Private Sub Command1_Click()
Dim starttime As String
Dim endtime As String
Dim repairtime As Integer
Dim setuptime As Integer
Dim pmtime As Integer
Dim interval As Integer
Dim totaltime As Integer
starttime = "08:00"
endtime = "09:00"
interval = DateDiff("n", starttime, endtime)
repairtime = 40
setuptime = 20
pmtime = 0
totaltime = repairtime + setuptime + pmtime
If interval = totaltime Then
MsgBox "Times match"
Else
MsgBox "Times do not match"
End If
End Sub
-
Nov 27th, 2000, 01:24 PM
#7
Thread Starter
Addicted Member
Hey thanks jbart, that worked great! Is there a way I can stop the adding of the new record if the time does not match?
Thanks jeffro
-
Nov 27th, 2000, 01:41 PM
#8
Thread Starter
Addicted Member
Never mind I just made a call and used it in the if end if statement for the time calculation.
jeffro
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|