| View previous topic :: View next topic |
| Author |
Message |
martinw General User


Joined: 11 May 2004 Posts: 26 Location: Uppsala, Sweden
|
Posted: Tue May 18, 2004 11:45 am Post subject: Shell: Program execution doesn´t wait till shells finished |
|
|
I´m using the 'shell()' to call the powerpoint presentation viewer to view a presentation. The problem is that the program execution doesn´t stop and wait untill the presentation is finsihed. I.e. any code below the the code in the example will be executed even if the powerpoint viewer is still running. How can I make the program wait untill it is finished?
| Code: | | shell( "file:///c:/program/microsoft%20office/powerpoint%20viewer/pptview.exe", 3, FileName ) |
|
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Tue May 18, 2004 7:37 pm Post subject: |
|
|
Read section 17.133 of my macro document. I have a long explanation with examples. I have not spent much time looking at this, but you should be able to set the bsync argument to wait. Worst case, look up the shell command in the included document. _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1569 Location: Frankfurt, Germany
|
Posted: Tue May 18, 2004 8:17 pm Post subject: |
|
|
try to use a 'while.. wend' or do 'while... loop' Loop that checks if a certain Frame is active or a certain Window is shown on top of your screen (these are just hints).
Am I right that you use OOo as your start window and the ppt presentation in between before your 'show' (or whatever it is) comes back to OOo?
If so then you can do a whole bunch of checks (you can use just one check), one of the easiest checks would be to check whether the Stardesktop.CurrentComponent supports the Service "com.sun.star.document.OfficeDocument" and wrap the if statement into a small loop, that always loops after you have called the PPT Program but breaks out of the loop when the condition (Starkdesktop.CurrentComponent.supportsService("com.sun.star.document.OfficeDocument") turns out to be true.
But if you use the check I mentioned be sure to use the ON ERROR GOTO 0 or ON ERROR GOTO <label>, cause otherwise you get a runtime error when the current window is no OOo window. _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1569 Location: Frankfurt, Germany
|
Posted: Tue May 18, 2004 9:17 pm Post subject: |
|
|
Okay I have tried some stuff and the following macro should do it:
| Code: | Sub stop_resumeOOo( )
'this procedure opens up the windows explorer (on a winnt os), does nothing (no statements, no calls) when OOo has no focus,
'and resumes the execution when OOo gains focus again
ON ERROR RESUME NEXT 'Stardesktop.CurrentComponent would throw an error, when no OOo component has the focus
Shell("C:\winnt\explorer.exe", 1)
Wait 3000 'opening the app might need some time, define the waittime how long you want it (for your ppt file probably 4-6 seconds loading time)
Do until Stardesktop.CurrentComponent.supportsService("com.sun.star.document.OfficeDocument")
'empty loop! Although execution continues, nothing really happens
Loop
'do whatever you want here
msgbox "back in OpenOffice"
End Sub
|
The only situation when an OpenOffice component gets the focus and it is not breaking out of the loop is when that component is your Basic IDE. Of course that can be easily fixed by adding a second condition, but for your purpose it should be fine. _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
bitfarmer General User

Joined: 06 May 2004 Posts: 39 Location: Murcia, Spain
|
Posted: Wed May 19, 2004 12:02 am Post subject: |
|
|
Cybb20, just to make your code faster, place a small wait inside the empty loop, as looping in a empty loop can easily consume the 100% of your CPU, more if it has to check for focused or similar (internal messages will fill the windows queu of events).
I say it by experience, not in OO basic, but in many other languajes happens like this.. |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1569 Location: Frankfurt, Germany
|
Posted: Wed May 19, 2004 6:38 am Post subject: |
|
|
you're right here is the modified code, that has no performance issues (CPU performance tested). Thanks!
| Code: |
Sub stop_resumeOOo( )
'this procedure opens up the windows explorer (on a winnt os), does nothing when OOo has no focus,
'and resumes the execution when OOo gains focus again
ON ERROR RESUME NEXT 'Stardesktop.CurrentComponent would throw an error, when no OOo component has the focus
Shell("C:\winnt\explorer.exe", 1)
Wait 3000 'opening the app might need some time, define the waittime how long you want it (for your ppt file probably 4-6 seconds loading time)
Do until Stardesktop.CurrentComponent.supportsService("com.sun.star.document.OfficeDocument")
wait 200
Loop
'do whatever you want here
msgbox "back in OpenOffice"
End Sub
|
_________________ - Knowledge is Power - |
|
| Back to top |
|
 |
|