OOBasic timer without a do loop

Creating Extension - 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 forum is not for asking questions about writing your own macros.

OOBasic timer without a do loop

Postby JeJe » Mon Mar 08, 2021 4:03 pm

There are several threads with people looking for an OOBasic timer... without an entirely satisfactory solution... and this probably isn't either... but its slightly different from putting a wait statement in a loop.

It requires a dialog and a commandbutton. The alternative to the loop statement is to keep firing the commandbutton execute from within the macro it calls. No global variables are needed to stop the execution.

Seems okay to me but may or may not be very stable.
Attachments
timer.odt
(12.68 KiB) Downloaded 51 times
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1533
Joined: Wed Mar 09, 2016 2:40 pm

Re: OOBasic timer without a do loop

Postby Villeroy » Mon Mar 08, 2021 4:31 pm

Same problem as with the do...wait...loop. There is no threading in StarBasic. The IDE is locked and you can not run other macros while the clock is running.
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
User avatar
Villeroy
Volunteer
 
Posts: 29704
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: OOBasic timer without a do loop

Postby JeJe » Mon Mar 08, 2021 4:54 pm

You can run other macros... you can do that with a do loop running as well.

Edit: if it was just a do loop without a wait statement then you couldn't run another macro while it was running but the wait statement yields. The trick I've used yields somewhere as well - the wait statement isn't needed for that - but the CPU usage goes from 0% to 50% on mine without it.

The problem with wait and waituntil is you might have tried closing the application down or something in the middle of the wait. And with the loop, its getting out of it.

(I've just run a test with doevents in a do loop and that doesn't allow another macro to run)
Attachments
timer.odt
(12.75 KiB) Downloaded 59 times
Last edited by JeJe on Mon Mar 08, 2021 6:09 pm, edited 1 time in total.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1533
Joined: Wed Mar 09, 2016 2:40 pm

Re: OOBasic timer without a do loop

Postby Villeroy » Mon Mar 08, 2021 6:03 pm

You are right. It is possible. I failed running code from the IDE while the clock was running. It is possible from the organizer or from Tools>Macros>Run.
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
User avatar
Villeroy
Volunteer
 
Posts: 29704
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: OOBasic timer without a do loop

Postby JeJe » Mon Mar 08, 2021 6:12 pm

Yeah, you're right, there's a difference between running from the IDE and otherwise. Running my Doevents test from Tools menu, Doevents does also allow other macros to run.

Edit: the dialog can be modal or non modal - I've just used the easiest to create.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1533
Joined: Wed Mar 09, 2016 2:40 pm

Re: OOBasic timer without a do loop

Postby JeJe » Tue Mar 09, 2021 1:47 pm

Adapting the code back to the loop method needs something like below.
I've had problems with the code still running with the do/wait/loop method when the dialog has been closed. It needs an error handler and a test of dialog visibility.

Code: Select all   Expand viewCollapse view

Sub Main
dlg  = loaddialog("Standard","Dialog2")
'START THE TIMER BY CALLING EXECUTE METHOD OF THE COMMAND BUTTON USING THE ACCESSIBLECONTEXT
dlg.getcontrol("CommandButton1").accessiblecontext.doaccessibleaction(0)
dlg.execute
End Sub

sub fnt2(ev) 'CALLED ON THE COMMANDBUTTON EXECUTE
dim t,mm,dlg,vis
dlg = ev.source.getcontext
on error goto hr
mm= ev.source.getcontext.model
do
vis =  dlg.isvisible
if vis =false then exit do
t = time
if mm.title<> t then mm.title =t
wait 500
loop
hr:
end sub

Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1533
Joined: Wed Mar 09, 2016 2:40 pm


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 3 guests