Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to wait until a certain time(eg. 15:20) given by the user

Status
Not open for further replies.

geros1

Technical User
Jan 17, 2005
12
ES
Hi. I am kind of new in VB6.
I would like to make to program in which the user gives: the time to start a procedure (time1) and the time to end it (time2).
How can I make the program to wait until time1 = the current time and then initiate a procedure? and how can i make the procedure to be repited until time2= current time?
Thank you in advance
 
Hi,

You can use a timer control. You set the interval of the timer to be however many milliseconds you want and have it check to see if the time has been reached.

Code:
Private Sub Timer1_Timer()
If Format(Now(), "dd/mm/yyyy hh:mm:ss") = <USER SPECIFIED TIME> then
Timer1.Enabled = False
[green]'Run procedure[/green]
End If
End Sub

You can loop through the procedure after it has started until it hits the end time specified by the user.

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
dear friend I do this but it doesn´t work!

Private Sub ButoEXE_Click()
datei = Text1.Text
Timer1.Enabled = True
end sub

Private Sub Timer1_Timer()
If Format(Now, "short Time") = datei Then
Timer1.Enabled = False
Calendar1.Print "1"
End If
End Sub

Thank you for your help
 
Hi,

Try this...

Code:
Private Sub ButoEXE_Click()
datei = Text1.Text
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
[green]'You can format the date however the user wishes e.g. 17/01/2005 15:20[/green]
If Format(Now, "dd/mm/yyyy hh:mm") = datei Then
Timer1.Enabled = False
MsgBox "Harley's Code Worked!"
End If
End Sub

Hope this helps

Harleyquinn

---------------------------------
For tsunami relief donations
 
If the user is entering 15:20 into the text box then it will never be equal. For the code above to work, the user would have to enter the extact date and time (as text).
 
Assuming the procedure will run on the same day you could change the format to:

Format(Now,"hh:mm")

That will pick up the time. As I mentioned the format can be changed to whatever the user will be inputing.

Possibly a DateTimePicker might force some conformity with the dates??

Harleyquinn

---------------------------------
For tsunami relief donations
 
I would convert the values into a date/time variable and not compare as text.
 
Fair cop, that's a good call bjd4jc.

Although the comparison as text does work it might well not be the best way to do it.

Just for my own information what are the drawbacks of comparing as text vs comparing as a date??

Harleyquinn

---------------------------------
For tsunami relief donations
 
hi again!
I dont understand why this doesn´t work. i write in the textbox the time eg. 15:43 but it still doesnt disable the timer when that time comes! it keeps on going without doing anything...

Private Sub ButoEXE_Click()
datei = Text1.Text
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
If Format(Now, "hh:mm") = datei Then
Timer1.Enabled = False
MsgBox "Harley's Code Worked!"
End If
End Sub


thank you again for your time
 
well the exact code I enter is this:

Private Sub ButoEXE_Click()
datei = Text1.Text
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
If Format(Now, "hh:mm") = datei Then
Timer1.Enabled = False
MsgBox "Harley's Code Worked!"
End If
End Sub

but again it doesn´t work and I don´t understand it. I enter the time in textbox in this form 15:40
 
What have you got datei declared as???

If it is a string the above code should work.

If it is a date this will work (however i am not recommending this as the best way to do it):

Code:
If Format(Now, "hh:mm") & ":00" = datei Then

I would also take the

Code:
Timer1.Interval = 1000
line out and set the timer interval property at design time in the properties window.

Harleyquinn

---------------------------------
For tsunami relief donations
 
I had declared datei as a string. and also I tried the other way you showed me by declaring it as a date variable. but still nothing. its a mystery..
 
Hmmm...

I can see nothing wrong with the code. In fact it works perfectly on my machine.

You could put a breakpoint on the timer control and see when it fires what values are being returned by datei?

Harleyquinn

---------------------------------
For tsunami relief donations
 
sometimes the answer is much simpler...just an error in declaring the variable...thank for our help and your time
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top