Results 1 to 11 of 11

Thread: Help need using a timmer.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Help need using a timmer.

    Hi all i want use timer or any good vb6 tool that allow me do this. I have a lable inside my form and it shows number of seconds lift and after like 30 seconds it pops up a massage or do an action such as closing a winow . I be happy if some on show me how i can achive this .Thanks

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Help need using a timmer.

    what ever you want to do put that code inside the
    VB Code:
    1. Private Sub Timer1_Timer()
    2.     Label1.Caption = Format(Time, "HH:NN:SS")
    3. End Sub
    Set the Timer1.Interval = 10
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help need using a timmer.

    Quote Originally Posted by ganeshmoorthy
    what ever you want to do put that code inside the
    VB Code:
    1. Private Sub Timer2_Timer()
    2.     Label1.Caption = Format(Time, "HH:NN:SS")
    3. End Sub
    Set the Timer1.Interval = 10
    thank u for reply. I tried this :


    VB Code:
    1. Private Sub Command1_Click()
    2. Timer1.Interval = 10
    3. Timer1.Enabled = True
    4. End Sub
    5. Private Sub Timer2_Timer()
    6.     Label1.Caption = Format(Time, "HH:NN:SS")
    7.  
    8.    [B]msgbox "20 seconds time is up.bye"[/B]
    9. Timer2.Enabled = False
    10. End Sub


    it pops up the massagebox so fast. i want after 20 seconds this code fires Command1_Click() instead of massagebox. could u show me how to activate Command1_Click() after 20 seconds?then waits untill it finds another
    application with this info FindWindow("SEINFELD_SUPERMAN", vbNullString)
    and keep that running for 20 seconds and close it again. I want my program to wait till it finds the window with that classe name to apear and then keep it running for 20 seconds and close it . I want this happens on and on untill i close the application.Thanks


    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    2. (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3.  
    4. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    5. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    6.                 ByVal hwnd As Long, _
    7.                 ByVal wMsg As Long, _
    8.                 ByVal wParam As Long, _
    9.                 ByVal lParam As Long) As Long
    10. Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    11. Private Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
    12. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    13.  Const WM_COMMAND = &H111
    14.  Private Const WM_CLOSE As Long = &H10
    15.  Private Const WM_KEYDOWN = &H100
    16. Private Const WM_KEYUP = &H101
    17.  Private Const VK_SPACE = &H20
    18.  
    19. [B]Private Sub Command1_Click()[/B]
    20. Dim window As Long
    21.  
    22. window = FindWindow("SEINFELD_SUPERMAN", vbNullString)
    23. PostMessage window, WM_COMMAND, 32831, 0
    24.  
    25.  
    26. End Sub
    27.  
    28. Private Sub Timer1_Timer()
    29. Dim x As Long, editx As Long
    30. Dim button As Long
    31.  
    32.  x = FindWindow("#32770", "Exit?")
    33.    button = FindWindowEx(x, 0&, "Button", "&Yes")
    34.    Call SendMessageLong(button, WM_KEYDOWN, VK_SPACE, 0&)
    35.    Call SendMessageLong(button, WM_KEYUP, VK_SPACE, 0&)
    36. End Sub
    Last edited by tony007; Jul 1st, 2006 at 01:05 AM.

  4. #4
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Help need using a timmer.

    here is the timer part ..

    VB Code:
    1. Private iTime As Integer
    2.    
    3. Private Sub Command1_Click()
    4.     Timer1.Interval = 1000
    5.     Timer1.Enabled = True
    6. End Sub
    7.  
    8. Private Sub Timer1_Timer()
    9.     iTime = iTime + 1
    10.     Debug.Print iTime
    11.     If iTime >= 20 Then
    12.         Debug.Print "END!"
    13.         Timer1.Interval = 0
    14.         Timer1.Enabled = False
    15.     End If
    16. End Sub

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help need using a timmer.

    Quote Originally Posted by rory
    here is the timer part ..

    VB Code:
    1. Private iTime As Integer
    2.    
    3. Private Sub Command1_Click()
    4.     Timer1.Interval = 1000
    5.     Timer1.Enabled = True
    6. End Sub
    7.  
    8. Private Sub Timer1_Timer()
    9.     iTime = iTime + 1
    10.     Debug.Print iTime
    11.     If iTime >= 20 Then
    12.         Debug.Print "END!"
    13.         Timer1.Interval = 0
    14.         Timer1.Enabled = False
    15.     End If
    16. End Sub

    rory this is running for ever i do not get End after 20 seconds!!. I mean 20 seconds how i can make it 20 seconds and at the end of 20 second the program call my Command1_Click() atomatically to do its job?

  6. #6
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Help need using a timmer.

    That runs for 20 seconds then ends the timer...check the Intermediate window.. it prints each second then ends the timer after it reaches 20 ..

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help need using a timmer.

    Quote Originally Posted by rory
    That runs for 20 seconds then ends the timer...check the Intermediate window.. it prints each second then ends the timer after it reaches 20 ..
    Man it does not. i keeps printed 1 and 1 .... forever !!!!!!!!!!!!!!! do i need to change my timmer property some how ?

  8. #8
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Help need using a timmer.

    delete the timer ... add a new Timer1 ...

    then try it ..
    also make sure iTime is Declared at the top of the Form ..

    Optionally this does the same thing ..

    VB Code:
    1. Private StartTime As Integer
    2. Private EndTime As Integer
    3.  
    4. Private Sub Command1_Click()
    5.     StartTime = FormatNumber(Timer, 0)
    6.     Timer1.Interval = 1000
    7.     Timer1.Enabled = True
    8. End Sub
    9.  
    10. Private Sub Timer1_Timer()
    11.     EndTime = FormatNumber(Timer, 0)
    12.     Debug.Print EndTime
    13.     If EndTime - StartTime >= 20 Then
    14.         Debug.Print "END!"
    15.         Timer1.Interval = 0
    16.         Timer1.Enabled = False
    17.     End If
    18. End Sub

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help need using a timmer.

    ror thank u for u help. the only problem is not that that my timer2 is not doing it job !! It does not click exist confirmation &Yes button !!!i be happy if u tell me what i am doing wrong.Thanks

    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    2. (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3.  
    4. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    5. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    6.                 ByVal hwnd As Long, _
    7.                 ByVal wMsg As Long, _
    8.                 ByVal wParam As Long, _
    9.                 ByVal lParam As Long) As Long
    10. Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    11. Private Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
    12. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    13.  Const WM_COMMAND = &H111
    14.  
    15.  Private iTime As Integer
    16.  
    17.  Private Const WM_CLOSE As Long = &H10
    18.  Private Const WM_KEYDOWN = &H100
    19. Private Const WM_KEYUP = &H101
    20.  Private Const VK_SPACE = &H20
    21.  
    22. Private Sub Command2_Click()
    23. Dim window As Long
    24.  
    25. window = FindWindow("SEINFELD_SUPERMAN", vbNullString)
    26. PostMessage window, WM_COMMAND, 32831, 0
    27.  
    28.  
    29. End Sub
    30.  
    31. Private Sub Timer1_Timer()
    32. [B]Dim x As Long, editx As Long ====> this block does not get executed at all!
    33. Dim button As Long
    34.  
    35.  x = FindWindow("#32770", "Exit?")
    36.    button = FindWindowEx(x, 0&, "Button", "&Yes")
    37.    Call SendMessageLong(button, WM_KEYDOWN, VK_SPACE, 0&)
    38.    Call SendMessageLong(button, WM_KEYUP, VK_SPACE, 0&)[/B]
    39. End Sub
    40.  
    41.  
    42.  
    43. Private Sub Command1_Click()
    44.     Timer2.Interval = 1000
    45.     Timer2.Enabled = True
    46.    
    47. [B]    Timer1.Enabled = True[/B]
    48. End Sub
    49.  
    50.  
    51.  
    52. Private Sub Timer2_Timer()
    53.   iTime = iTime + 1
    54.     Debug.Print iTime
    55.     If iTime >= 20 Then
    56.         Debug.Print "END!"
    57.        [B] Command2_Click[/B]
    58.         Timer2.Interval = 0
    59.         Timer2.Enabled = False
    60.     End If
    61. End Sub

  10. #10
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Help need using a timmer.

    You need to set an interval for Timer1 in your case so it will start ..
    I Dont know how often you want it to run but 1000 for example would be 1 second approx ..

    Timer2.Interval = 1000
    Timer2.Enabled = True
    Timer1.Interval = 1000
    Timer1.Enabled = True

    If I understand you want one thing to get posted once only, after 20 seconds (SEINFELD_SUPERMAN) and the other one which is in Timer 1 every second ...?

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help need using a timmer.

    Quote Originally Posted by rory
    You need to set an interval for Timer1 in your case so it will start ..
    I Dont know how often you want it to run but 1000 for example would be 1 second approx ..

    Timer2.Interval = 1000
    Timer2.Enabled = True
    Timer1.Interval = 1000
    Timer1.Enabled = True

    If I understand you want one thing to get posted once only, after 20 seconds (SEINFELD_SUPERMAN) and the other one which is in Timer 1 every second ...?

    Many thanks for u help.That fixed the problem.

    My whole intention is to run my application for 20 seconds then close it and then open it again again and run it again for 20 second ... untill i click a stop button. Now i start the one time process by clicking a command button1 .

    Could u help me to modify the code so that after complete load of my application it renew the 20 seconds and do the process again and again untill i click a stop button. Complete load up occurs when a window with the following information apears :

    hParent = FindWindow("SEINFELD_SUPERMAN", "Welcome to my app"

    So between load of app and complete login in there is 20 seconds gap showing prograss bar and the main application window pops up.Thanks

    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    2. (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3.  
    4. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    5. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    6.                 ByVal hwnd As Long, _
    7.                 ByVal wMsg As Long, _
    8.                 ByVal wParam As Long, _
    9.                 ByVal lParam As Long) As Long
    10. Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    11. Private Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
    12. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    13.  Const WM_COMMAND = &H111
    14.  
    15.  Private iTime As Integer
    16.  'Constants Declarations
    17. Private Const BM_CLICK As Long = &HF5    'To click a button
    18.  
    19.  Private Const WM_CLOSE As Long = &H10
    20.  Private Const WM_KEYDOWN = &H100
    21. Private Const WM_KEYUP = &H101
    22.  Private Const VK_SPACE = &H20
    23.  
    24. 'This function when it is called it tries to close my appliction
    25. Private Sub Command2_Click()
    26. Dim window As Long
    27.  
    28. window = FindWindow("SEINFELD_SUPERMAN", vbNullString)
    29. PostMessage window, WM_COMMAND, 32831, 0
    30.  
    31.  
    32. End Sub
    33.  
    34.  
    35. ''this will click yes to closing confirmation when it pops up
    36. ''and also re opens my application again
    37. Private Sub Timer1_Timer()
    38. Dim x As Long, editx As Long
    39. Dim button As Long
    40.  
    41.  x = FindWindow("#32770", "Exit?")
    42.    button = FindWindowEx(x, 0&, "Button", "&Yes")
    43.    Call SendMessageLong(button, WM_KEYDOWN, VK_SPACE, 0&)
    44.    Call SendMessageLong(button, WM_KEYUP, VK_SPACE, 0&)
    45.      
    46.  'after complet close of my application . It loads it again for a new 20 sec session
    47.   If x Then
    48.        ' SendMessage x, WM_CLOSE, 0&, 0&
    49.         Shell "C:\Program Files\my.\xyz.exe"
    50.        
    51.       [B] Call main[/B]==> clicks on my new applicaton button login
    52.        
    53.     End If
    54. End Sub
    55.  
    56.  
    57. 'starts a new 20 seconds session life time for my application
    58. [B]Private Sub Command1_Click()
    59.     Timer2.Interval = 1000
    60.     Timer2.Enabled = True
    61.    
    62.     'Timer1.Enabled = True
    63.     Timer1.Interval = 1000
    64.     Timer1.Enabled = True
    65.  
    66.    
    67. End Sub[/B]
    68.  
    69.  
    70. Private Sub Timer2_Timer()
    71.   iTime = iTime + 1
    72.     Debug.Print iTime
    73.     If iTime >= 10 Then
    74.         Debug.Print "END!"
    75.        [B] Command2_Click[/B]= calls command 2 to close my application
    76.         Timer2.Interval = 0
    77.         Timer2.Enabled = False
    78.     End If
    79. End Sub
    80.  
    81. Sub main()
    82. Dim hParent As Long
    83. Dim hChild As Long
    84.    
    85.  
    86.          Do
    87.                    hParent = FindWindow("#32770", "Welcome")
    88.                   DoEvents
    89.         Loop Until hParent
    90.  
    91.  
    92.     If Not hParent = 0 Then
    93.         'To find the button in pARENT window
    94.         hChild = FindWindowEx(hParent, 0, "Button", "&Login")
    95.         'If button found then click it.
    96.         If hChild <> 0 Then
    97.             'Now we clicked the button
    98.             Call SendMessage(hChild, BM_CLICK, 0, 0)
    99.         End If
    100.     End If
    101.    
    102.    
    103. End Sub
    Last edited by tony007; Jul 1st, 2006 at 04:20 AM.

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