« Basic Functions: INDEX, MATCH | Main | Database functions: DAVERAGE »

November 12, 2004

Macros: A simple clock

Here is another simple macro that turns an OOo Calc spreadsheet into a real time clock.

The OpenOffice Basic builtin function Now returns the current date and time as a Date value. By embedding this function inside an infinite WHILE loop, we simulate a clock. The code is shown below.

Sub DisplayTime
Dim oDoc As Object
Dim oSheet As Object
Dim oCell As Object

oDoc=ThisComponent
oSheet=oDoc.Sheets.getByName("Sheet1")
) oCell=oSheet.getCellByposition(1,1) 'B2
Do
oCell.SetString(Now)
Wait 1000
Loop While 1
End Sub


The output to the spreadsheet is shown below.

clock.jpg

Posted by Dave at November 12, 2004 04:57 AM

Comments

Post a comment




Remember Me?