countdown timer

0lzi

New Member
Joined
Sep 13, 2011
Messages
26
2sbrf42.png


here is a picture to help visualise what im trying to do.

im trying to get the system time, then getting time from the user from inputbox, then display the difference in a shapes text box and loop untill the timeleft = 0

code i have so far:
Code:
Sub RoundedRectangle1_Click()

Dim setTimer
Dim currentTime
Dim timeLeft As Single

setTimer = InputBox("Please enter a Time seperated by : eg. hr:min:sec")

currentTime = Time

timeLeft = setTimer - currentTime

With ActiveSheet.Shapes("Rounded Rectangle 1") _
.TextFrame.Characters.Text = ("& timeLeft &")
End With

End Sub

i have not included a loop yet i am just wanting to display the time difference, between the two times.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
This worked for me:

Code:
Sub RoundedRectangle1_Click()
    Dim setTimer
    Dim currentTime As Date
    Dim timeLeft As Date
    setTimer = InputBox("Please enter a Time seperated by : eg. hr:min:sec")
    currentTime = Time
    timeLeft = TimeValue(setTimer) - currentTime
    With ActiveSheet.Shapes("Rounded Rectangle 1")
        .TextFrame.Characters.Text = "(" & timeLeft & ")"
    End With
End Sub
 
Upvote 0
that worked but the text box shows the ( ) so i took them out, now i need to find out how to loop it,

im guessing i would have
Code:
do while timeLeft >0
or somthing?

any help on that?
 
Upvote 0
seems i need some help with my loops, this one seems to be an infinite loop as it crashes excel hard :eeek:

code:

Code:
Sub RoundedRectangle1_Click()
    Dim setTimer
    Dim currentTime As Date
    Dim timeLeft As Date
    
    
    setTimer = InputBox("Please enter a Time seperated by : eg. hr:min:sec")
    currentTime = Time
    timeLeft = TimeValue(setTimer) - currentTime
   Do
    With ActiveSheet.Shapes("Rounded Rectangle 1")
        .TextFrame.Characters.Text = "" & timeLeft & ""
    End With
    Loop Until timeLeft >= ("00:00:00")
    
End Sub
 
Upvote 0
i cant seem to get the text to update properly.

i have tried running another procedure that calls the "Sub RoundedRectangle1_Click()" but the problem is that it makes me enter the 'setTimer' value again
 
Upvote 0
managed to do it slightly differently..

code:
Code:
Sub RoundedRectangle1_Click()
    Dim setTimer
    Dim currentTime As Date
   Dim timeLeft As Date
    
    setTimer = InputBox("Please enter a Time seperated by : eg. hr:min:sec")
    Do While timeLeft >= ("00:00:00")
    currentTime = Time
    timeLeft = TimeValue(setTimer) - currentTime
    With ActiveSheet.Shapes("Rounded Rectangle 1")
        .TextFrame.Characters.Text = "" & timeLeft & ""
    End With
    Application.Wait Now + TimeValue("00:00:01")
    
 Loop
    
End Sub

i just need to do an 'IF' in the loop that states, if the application close timeLeft = ("00:00:00") and that should break the loop right?
 
Upvote 0
If you do it that way you won't be able to use your worksheet while the macro is running. Is that what you want?
 
Upvote 0
for now yes, i have just picked up doing vba for my job so im learning it :) its very different from the directX C++ stuff i did in uni, so programming isnt my weak point its just learning a different way of programming from OO C++ lol

thanks alot for your help,

im sure this forum will come in handy for my next little project for learning vba
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top