[Calc] Coundown Timer

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
VBWizard
Posts: 8
Joined: Sat May 14, 2016 5:05 pm

[Calc] Coundown Timer

Post 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
Last edited by VBWizard on Sun May 15, 2016 6:56 pm, edited 2 times in total.
OpenOffice 4.1.2 on Windows XP
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Coundown Timer

Post by Villeroy »

countdown.ods
Simple countdown
(15.56 KiB) Downloaded 1415 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
VBWizard
Posts: 8
Joined: Sat May 14, 2016 5:05 pm

Re: [Solved] Coundown Timer

Post by VBWizard »

Note: If using "option explicit", nNewTime and nStartTime should be declared as "long", not "integer", and really should be lNewTime and lStartTime.
OpenOffice 4.1.2 on Windows XP
Post Reply