set timer with a variable

bbxrider

New Member
Joined
Jan 26, 2015
Messages
4
trying to start a sheet update routine with the timer using a variable. see code below, when I try the hard code that works with a variable it doesn't start the timer, perhaps a different way to start the timer?

Public Sub startTimer()

'... the following is the procedure to run on the timer'
saveRTDinfo 'Sub saveRTDinfo()

alertTime = alertTime 'for debugging to view value
alertTime = now + TimeValue(alertTime) 'don't work see next line

'debug.print "alertTime = " & alertTime, this prints 00:02:00, literally, without parens
alertTime = now + TimeValue("00:02:00") 'this works

'Application.OnTime alertTime, "EventMacro" this worked
Application.OnTime EarliestTime:=alertTime, _
Procedure:="startTimer", schedule:=True
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
try this - see what it prints. What is the value of the first alertTime variable? Where does it come from? And what is its type?
VBA Code:
...
alertTime = alertTime
debug.print "alertTime1 = " & alertTime, Typename(alertTime)
alertTime = now + TimeValue(alertTime)
debug.print "alertTime2 = " & alertTime
alertTime = now + TimeValue("00:02:00")
debug.print "alertTime3 = " & alertTime
...
 
Upvote 0
h
try this - see what it prints. What is the value of the first alertTime variable? Where does it come from? And what is its type?
VBA Code:
...
alertTime = alertTime
debug.print "alertTime1 = " & alertTime, Typename(alertTime)
alertTime = now + TimeValue(alertTime)
debug.print "alertTime2 = " & alertTime
alertTime = now + TimeValue("00:02:00")
debug.print "alertTime3 = " & alertTime
...
thanks for the reply

here's the variable definitions
Public alertTime As Variant
Public alertTimeHH As String
Public alertTimeMM As String
Public alertTimeSS As String

here's how I configured:
alertTimeHH = InputBox("update time interval hours, default = 00", "00")
alertTimeMM = InputBox("update time interval minutes, default = 00", "00")
alertTimeSS = InputBox("update time interval seconds, default = 00", "00")
testStr = """" & alertTimeHH & ":" & alertTimeMM & ":" & alertTimeSS & """"
alertTime = alertTimeHH & ":" & alertTimeMM & ":" & alertTimeSS
Debug.Print "testStr = " & testStr
Debug.Print "alertTime = " & alertTime

this is the results from the immediate window, from above I entered 02 for MM
testStr = "00:02:00"
alertTime = 00:02:00

here's your suggestions results from immediate window, I entered 00 for all inputs:
alertTime1 = 00:00:00 String
alertTime2 = 3/20/2024 8:47:50 PM
alertTime3 = 3/20/2024 8:50:07 PM

Prolly some simple change... at least I hope
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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