Page 1 of 1

[Calc] Coundown Timer

Posted: Sat May 14, 2016 5:20 pm
by VBWizard
This is a working Timer for Calc, that counts down in seconds.
Note that the Initial Time and the displayed countdown are in cell M10; this can be changed to suit users preference, but note there are TWO points in the code to change:
Firstly the "m10" in line 5 and secondly, the "12,9" in line 22.

Code: Select all

Sub Countdown()
	Doc = ThisComponent
	Sheet = Doc.Sheets(0)
	' ** Get Limit
	strTime=Sheet.getCellRangeByName("m10").getString()  ' the 1st change point to use a different cell
	nTime=val(strTime)
	nStartTime=Timer
	nNewTime= nStartTime
	Do Until nTime=0
		 Do while nStartTime=nNewTime
			n NewTime=timer
		 Loop
		nTime=nTime-1
		nStartTime=nNewTime
		Update
	Loop
	done ' you can get rid of this sub and put something more exciting in.
End Sub
Sub Update ()
	Doc = ThisComponent
	Sheet = Doc.Sheets(0)
	Cell = Sheet.getCellByPosition( 12,9)   ' the second change point
	Cell.string=str(nTime)
End Sub
Sub done()
	msgbox ("Out Of Time, Sorry",0,"Time UP")
End Sub

Re: Coundown Timer

Posted: Sat May 14, 2016 5:48 pm
by Villeroy
countdown.ods
Simple countdown
(15.56 KiB) Downloaded 1573 times

Re: [Solved] Coundown Timer

Posted: Mon May 16, 2016 10:24 pm
by VBWizard
Note: If using "option explicit", nNewTime and nStartTime should be declared as "long", not "integer", and really should be lNewTime and lStartTime.