Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i write a pragram that click a mouse
now i want user can input a time and when the current time set the program run
can u help me?


Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If DateTime.Now = X Then
LEFTCLICK()
End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Timer1.Enabled = True

End Sub
but this dont work

What I have tried:

hi
i write a pragram that click a mouse
now i want user can input a time and when the current time set the program run
can u help me?


  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If DateTime.Now = X Then
            LEFTCLICK()
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Timer1.Enabled = True

    End Sub
but this dont work
Posted
Updated 9-Jun-20 23:52pm
Comments
ZurdoDev 9-Jun-20 14:56pm    
What is your question?
momo22007 10-Jun-20 0:44am    
my question is how set a timer that will run code at a certain time ?
Ralf Meier 10-Jun-20 1:03am    
at first : to compare DateTime.Now exactly will not work - notice that here are also Milliseconds included. A Match to a Millisecond-Value is nearly impossible ...
then : what should happen in your method "LEFTCLICK" ... or what are you trying to achieve ...?
momo22007 10-Jun-20 1:12am    
this left click the mouse
you reckon its minute
can u write this code?
CHill60 10-Jun-20 5:40am    
This is not a code writing service.

1 solution

In the tick event you should compare the difference between the current date and time and the datetime the user has entered.

There is an example in the book "Mastering Visual Basic .NET" by Evangelous Petroutsos ...
Listing 9.16[^]

The trick is not to check for equality (see the comment by @Ralf-Meier) - compare the difference between the current time and your user-entered time - again, see the example on the link.

Be aware that there are 4 Timer classes in .NET that behave differently - see the documentation here[^]

Finally, terminology counts .. you are saying that you have written a "program" to click a mouse. You have actually written some code to do that. The Timer is not running a program it is running your code that is in a separate function.

If you want to run a specific program at a specific time then you might be looking for something like Task Scheduler for developers - Win32 apps | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900