Results 1 to 8 of 8

Thread: Time calculation..??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Fremont Ohio 43420
    Posts
    253

    Question

    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

  2. #2
    Lively Member
    Join Date
    Nov 2000
    Posts
    73
    could u give the data of the textfields


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Fremont Ohio 43420
    Posts
    253
    StartTime = 8:00
    EndTime = 9:00

    RepairTime = 40
    SetupTime = 20
    PMTime = 0

    Those are some examples.

    jeffro

  4. #4
    Lively Member
    Join Date
    Nov 2000
    Posts
    73
    instead of val convert it time an try Cdate(txtEndTime,hh:mm) etc.. may u will get the solution

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Fremont Ohio 43420
    Posts
    253
    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

  6. #6
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    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

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Fremont Ohio 43420
    Posts
    253
    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

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Fremont Ohio 43420
    Posts
    253
    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
  •  



Click Here to Expand Forum to Full Width