Results 1 to 5 of 5

Thread: Time Compare

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    12

    Time Compare

    I looked thro many books and here, but can't find an answer to>
    How can I write a sub that looks at a time ("hh,mm, AM/PM) that I input into a text box, compare with PC time and provide a label text output?
    Thanks for any help.

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Time Compare

    Try something like this:
    Code:
    Public Sub Timecheck()
    Dim TimePC As Date
    Dim TimeInput As Date
    Dim Text As String
    TimePC = Time()
    Text = InputBox("Time:", "Input", 200, 200)
    TimeInput = TimeValue(Text)
    MsgBox "TimeDifference " & Format(TimeInput - TimePC, "hh:mm"), vbOKOnly, "OutValue"
    End Sub
    Note: The Input isn't checked to be a valid time!!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Time Compare

    Using a textbox to input a time (or date) value is not a wise move, because it is prone to errors and bugs.

    For an explanation of why, see the article Why are my dates not working properly? from our Classic VB FAQs (in the FAQ forum)

    For information about the kind of controls you should be using, see the article What controls can I use to input a date/time?

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    12

    Re: Time Compare

    Many thanks, having read thro my original post I don't think I made it clear, well I am 66 so the old grey matter is slow. I need an output when the PC and the input time coincides, i,e to start a process off.
    I take it that TimeInput is the name given to a textbox?
    Thanks

  5. #5
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Time Compare

    I didn't use a TextBox, I used an Inputbox instead, TimeInput gets the Time-Variable out of the String("Text") from the Inputbox.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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