|
-
Jul 1st, 2006, 12:22 AM
#1
Thread Starter
Frenzied Member
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
-
Jul 1st, 2006, 12:34 AM
#2
Re: Help need using a timmer.
what ever you want to do put that code inside the
VB Code:
Private Sub Timer1_Timer()
Label1.Caption = Format(Time, "HH:NN:SS")
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.
-
Jul 1st, 2006, 12:46 AM
#3
Thread Starter
Frenzied Member
Re: Help need using a timmer.
 Originally Posted by ganeshmoorthy
what ever you want to do put that code inside the
VB Code:
Private Sub Timer2_Timer()
Label1.Caption = Format(Time, "HH:NN:SS")
End Sub
Set the Timer1.Interval = 10
thank u for reply. I tried this :
VB Code:
Private Sub Command1_Click()
Timer1.Interval = 10
Timer1.Enabled = True
End Sub
Private Sub Timer2_Timer()
Label1.Caption = Format(Time, "HH:NN:SS")
[B]msgbox "20 seconds time is up.bye"[/B]
Timer2.Enabled = False
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:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
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
Private Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
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
Const WM_COMMAND = &H111
Private Const WM_CLOSE As Long = &H10
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const VK_SPACE = &H20
[B]Private Sub Command1_Click()[/B]
Dim window As Long
window = FindWindow("SEINFELD_SUPERMAN", vbNullString)
PostMessage window, WM_COMMAND, 32831, 0
End Sub
Private Sub Timer1_Timer()
Dim x As Long, editx As Long
Dim button As Long
x = FindWindow("#32770", "Exit?")
button = FindWindowEx(x, 0&, "Button", "&Yes")
Call SendMessageLong(button, WM_KEYDOWN, VK_SPACE, 0&)
Call SendMessageLong(button, WM_KEYUP, VK_SPACE, 0&)
End Sub
Last edited by tony007; Jul 1st, 2006 at 01:05 AM.
-
Jul 1st, 2006, 01:09 AM
#4
PowerPoster
Re: Help need using a timmer.
here is the timer part ..
VB Code:
Private iTime As Integer
Private Sub Command1_Click()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
iTime = iTime + 1
Debug.Print iTime
If iTime >= 20 Then
Debug.Print "END!"
Timer1.Interval = 0
Timer1.Enabled = False
End If
End Sub
-
Jul 1st, 2006, 01:18 AM
#5
Thread Starter
Frenzied Member
Re: Help need using a timmer.
 Originally Posted by rory
here is the timer part ..
VB Code:
Private iTime As Integer
Private Sub Command1_Click()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
iTime = iTime + 1
Debug.Print iTime
If iTime >= 20 Then
Debug.Print "END!"
Timer1.Interval = 0
Timer1.Enabled = False
End If
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?
-
Jul 1st, 2006, 01:22 AM
#6
PowerPoster
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 ..
-
Jul 1st, 2006, 01:28 AM
#7
Thread Starter
Frenzied Member
Re: Help need using a timmer.
 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 ?
-
Jul 1st, 2006, 01:29 AM
#8
PowerPoster
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:
Private StartTime As Integer
Private EndTime As Integer
Private Sub Command1_Click()
StartTime = FormatNumber(Timer, 0)
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
EndTime = FormatNumber(Timer, 0)
Debug.Print EndTime
If EndTime - StartTime >= 20 Then
Debug.Print "END!"
Timer1.Interval = 0
Timer1.Enabled = False
End If
End Sub
-
Jul 1st, 2006, 02:20 AM
#9
Thread Starter
Frenzied Member
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:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
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
Private Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
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
Const WM_COMMAND = &H111
Private iTime As Integer
Private Const WM_CLOSE As Long = &H10
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const VK_SPACE = &H20
Private Sub Command2_Click()
Dim window As Long
window = FindWindow("SEINFELD_SUPERMAN", vbNullString)
PostMessage window, WM_COMMAND, 32831, 0
End Sub
Private Sub Timer1_Timer()
[B]Dim x As Long, editx As Long ====> this block does not get executed at all!
Dim button As Long
x = FindWindow("#32770", "Exit?")
button = FindWindowEx(x, 0&, "Button", "&Yes")
Call SendMessageLong(button, WM_KEYDOWN, VK_SPACE, 0&)
Call SendMessageLong(button, WM_KEYUP, VK_SPACE, 0&)[/B]
End Sub
Private Sub Command1_Click()
Timer2.Interval = 1000
Timer2.Enabled = True
[B] Timer1.Enabled = True[/B]
End Sub
Private Sub Timer2_Timer()
iTime = iTime + 1
Debug.Print iTime
If iTime >= 20 Then
Debug.Print "END!"
[B] Command2_Click[/B]
Timer2.Interval = 0
Timer2.Enabled = False
End If
End Sub
-
Jul 1st, 2006, 02:36 AM
#10
PowerPoster
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 ...?
-
Jul 1st, 2006, 03:39 AM
#11
Thread Starter
Frenzied Member
Re: Help need using a timmer.
 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:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
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
Private Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
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
Const WM_COMMAND = &H111
Private iTime As Integer
'Constants Declarations
Private Const BM_CLICK As Long = &HF5 'To click a button
Private Const WM_CLOSE As Long = &H10
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const VK_SPACE = &H20
'This function when it is called it tries to close my appliction
Private Sub Command2_Click()
Dim window As Long
window = FindWindow("SEINFELD_SUPERMAN", vbNullString)
PostMessage window, WM_COMMAND, 32831, 0
End Sub
''this will click yes to closing confirmation when it pops up
''and also re opens my application again
Private Sub Timer1_Timer()
Dim x As Long, editx As Long
Dim button As Long
x = FindWindow("#32770", "Exit?")
button = FindWindowEx(x, 0&, "Button", "&Yes")
Call SendMessageLong(button, WM_KEYDOWN, VK_SPACE, 0&)
Call SendMessageLong(button, WM_KEYUP, VK_SPACE, 0&)
'after complet close of my application . It loads it again for a new 20 sec session
If x Then
' SendMessage x, WM_CLOSE, 0&, 0&
Shell "C:\Program Files\my.\xyz.exe"
[B] Call main[/B]==> clicks on my new applicaton button login
End If
End Sub
'starts a new 20 seconds session life time for my application
[B]Private Sub Command1_Click()
Timer2.Interval = 1000
Timer2.Enabled = True
'Timer1.Enabled = True
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub[/B]
Private Sub Timer2_Timer()
iTime = iTime + 1
Debug.Print iTime
If iTime >= 10 Then
Debug.Print "END!"
[B] Command2_Click[/B]= calls command 2 to close my application
Timer2.Interval = 0
Timer2.Enabled = False
End If
End Sub
Sub main()
Dim hParent As Long
Dim hChild As Long
Do
hParent = FindWindow("#32770", "Welcome")
DoEvents
Loop Until hParent
If Not hParent = 0 Then
'To find the button in pARENT window
hChild = FindWindowEx(hParent, 0, "Button", "&Login")
'If button found then click it.
If hChild <> 0 Then
'Now we clicked the button
Call SendMessage(hChild, BM_CLICK, 0, 0)
End If
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|