Results 1 to 17 of 17

Thread: Timer

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Resolved Timer

    I am going to make a timer that takes a message via an inputbox, then lets the user input a time via a text box and thes display the message that the inputbox got at the beginning in a message box, but I don't know how to make the message appear at the specified time. Here is my code, please help...

    Code:
    Option Explicit
    Dim intmsg As Integer
    Dim Txtstg As String
    
    Private Sub Command1_Click()
    If (Text1.Text = "") Or (Text1.Text = "- Time goes here -") Then
    MsgBox "You have to type a number in either minutes or seconds!", vbOKOnly + vbCritical, "Error"
    Else
    Form1.Visible = False
    End If
    End Sub
    
    Private Sub Form_Load()
    Txtstg = Trim(InputBox("What do you want your message to say?", "What your message says", "Type here..."))
    If Txtstg = "" Then
    End
    End If
    End Sub
    
    Private Sub Text1_Click()
    If Text1.Text = "- Time goes here -" Then
    Text1.Text = ""
    End If
    End Sub
    
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If (KeyAscii < 48) And (KeyAscii >= 32) Or (KeyAscii > 58) Then
    KeyAscii = 0
    End If
    If Text1.Text = "- Time goes here -" And (KeyAscii > 47) And (KeyAscii < 58) Then
    Text1.Text = ""
    End If
    End Sub
    I need to make the message appear when the clock reaches the user-inputted time.


    Thanks,
    Sir loin
    Last edited by Sir Loin; Apr 18th, 2005 at 05:31 PM.

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Timer

    All you'd have to do is get the current time using something like this:

    VB Code:
    1. Dim CurTime As String
    2. CurTime = Format(Time, "hh:mm:ss")

    That is presuming that they enter the date in a hour:minute:second format.

    Then, (Using a timer I suppose) check every 1000 miliseconds (1 second to you an me) - if they match then disable the timer and display the message


    Hoipe that helps,

    RyanJ
    My Blog.

    Ryan Jones.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: Timer

    Thanks for the help, but when I ask for the current time it says the time in military time, and the message doesn't appear when I type a time.

    The code i'm using is
    VB Code:
    1. if text1.text = curtime then
    2. do some stuff
    3. end if

    I am also using a timer to update the time every minute.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Timer

    Quote Originally Posted by Sir Loin
    Thanks for the help, but when I ask for the current time it says the time in military time
    I don't understand what you mean by "military time".

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: Timer

    well when it was 5:00 it would say 17:00, and now that it is 6:00 it says 18:00.

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Timer

    24-hour format is known as Military Time.

    Just add the AMPM and it will be correct.


    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim CurTime As String
    5.   CurTime = Format(Now, "h:mm:ss ampm")
    6.   CurTime = Left(CurTime, Len(CurTime) - 2) ' if you don't want the AMPM
    7. End Sub

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: Timer

    Thanks, but I need to know one more thing, how do I code a working clock that shows hours minutes and seconds?


    Thanks,
    Sir Loin

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: Timer

    Never mind, I made one...



    Thanks,
    Sir Loin

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Timer

    Quote Originally Posted by dglienna
    24-hour format is known as Military Time.
    Thanks, I didn't know that. I guess everone in my country is in the military then since we use the 24 hour system,

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    537

    Re: Timer

    I have one final question, how do i make a form "Always on top" so even when it doesn't have focus it is still on top.


    Thanks,
    Sir Loin

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Timer

    Quote Originally Posted by Sir Loin
    I have one final question, how do i make a form "Always on top" so even when it doesn't have focus it is still on top.
    That's a very common question. If you would have done a Forum search you would have found the code in no time. But here it is again:
    VB Code:
    1. Private Declare Function SetWindowPos Lib "user32.dll" ( _
    2.  ByVal hwnd As Long, _
    3.  ByVal hWndInsertAfter As Long, _
    4.  ByVal x As Long, _
    5.  ByVal y As Long, _
    6.  ByVal cx As Long, _
    7.  ByVal cy As Long, _
    8.  ByVal wFlags As Long) As Long
    9.  
    10. Private Const HWND_NOTOPMOST As Long = -2
    11. Private Const HWND_TOPMOST As Long = -1
    12. Private Const SWP_NOMOVE As Long = &H2
    13. Private Const SWP_NOSIZE As Long = &H1
    14.  
    15. Private Sub TopMost(Optional blnTopMost As Boolean = True)
    16.     Dim hwndAfter As Long
    17.     If blnTopMost Then
    18.         hwndAfter = HWND_TOPMOST
    19.     Else
    20.         hwndAfter = HWND_NOTOPMOST
    21.     End If
    22.     Call SetWindowPos(Me.hwnd, hwndAfter, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
    23. End Sub
    Simply call the TopMost sub. You can optionally pass True to set it topmost or False to not set it topmost (restore it). Default value is True.

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Timer

    Use SetParent, which you use like this:


    VB Code:
    1. Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    2.  
    3. SetParent Me.hWnd, frmMain.hWnd

    Where ME is the Child and frmMain is the Parent.

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Timer

    Quote Originally Posted by dglienna
    Use SetParent, which you use like this:
    SetParent will not make a Form topmost.

  14. #14
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Timer

    Hmmm. I have the SetParent in an MDI that does something like that. I'm going to save the SetWindow example.. Thanks.

  15. #15
    Addicted Member VbMafia's Avatar
    Join Date
    Sep 2004
    Location
    Pilipinas
    Posts
    177

    Re: Timer

    Code:
    Label1.Caption=format(time,"hh:mm:ss")
    " I never did anything worth doing entirely by accident.... Almost none of my inventions were derived in that manner. They were achieved by having trained myself to be analytical and to endure and tolerate hard work."

    " Many of life's failures are experienced by people who did not realize how close they were to success when they gave up. "
    - Thomas Alva Edison-

    In God We Trust

  16. #16
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Timer

    Are the clocks like this, too ?



  17. #17
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Timer

    Quote Originally Posted by dglienna
    Are the clocks like this, too ?
    LOL, yeah sure! All kidding aside if a time table say 15:00 there can't be any confusion about the time but the AM/PM can be misunderstood. I guess that's why your military use that system as most of Europe does, except for the UK.

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