Ask Your Question
0

Fast Macro code, how to interrupt, stop?

asked 2021-01-06 04:07:06 +0100

Phrance QueTara gravatar image

How to interrupt running Basic Macro code, when the main IDE-window does not have focus? The following example is rather silly, but illustrates my question. When running the script below from within the IDE by clicking the run button in the menu, then focus goes to the Msgbox, and "pretty much" stays there.

Sub EndlessMsgBox
    Do Until False
        Msgbox("Hello World")
    Loop
End Sub

These Interrupt-Attempts did not work:

  • Ctrl+Shif+Q does not work
  • Shift+F5 does not work
  • None of the IDE buttons nor pulldowns work, because don't have focus.
  • Can't exit IDE, because because doesn't have focus.

Any insight is appreciated. (LO 7.0.2.2, Windows 10)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2021-01-06 04:37:18 +0100

Ratslinger gravatar image

Hello,

You can set a breakpoint (circle with dot left of code line) then be able to step or cancel:

image description

See -> LibreOffice Basic IDE

and -> Integrated Development Environment (IDE)

edit flag offensive delete link more

Comments

Sure, I agree, break-points are great to use during debug, when planning to set them before running code, and when setting them upfront (basically when anticipating code issues).

But how to interrupt already running code, if the focus is not passed back to the IDE? (or, as in my silly example, if focus is only passed back to the IDE for a brief moment, not long enough for manual interrupts).

Assumptions:

  • No break-points were set
  • No other escape mechanisms added to the code itself

I could imagine that somewhere within LO exists some sort of an interrupt handler, where maybe custom keyboard shortcuts could be tied to setting specific interrupt flags, or similar. If the keyboard shortcut Ctrl+Shift+Q (or equivalent) was intended to do so, maybe its interrupt "rights" could somehow be "elevated or extended" to running code (in this particular example: the Msgbox routine).

Phrance QueTara gravatar imagePhrance QueTara ( 2021-01-06 18:57:38 +0100 )edit

I tried my example again.

This time neither the LO-Base-main-window, nor the IDE-window would take focus, so could not access any IDE or LO functions.

Probably could have killed it via Windows Task Manager [Ctrl+Alt+Del], but to get out of the running code, I did this:

  • Open a completely different LO_Base
  • Click Menu/Tool/Macro/Run Macrocs...
  • Select under [Library]: LibreOffice Macros/Access2Base/Methods/
  • Select under [Macro Name]: _Refresh
  • Click the [Run] button (this will throw an error, but don't care)
  • Go back into the IDE-window

Now, after clicking the [OK] button inside the Msgbox, code halts and lets me stop it.

Phrance QueTara gravatar imagePhrance QueTara ( 2021-01-06 19:13:08 +0100 )edit

Your conditions are not reasonable. In this case simply kill the process & fix the terrible code.

Ratslinger gravatar imageRatslinger ( 2021-01-06 19:19:19 +0100 )edit

Yes, indeed possible, as indicated in the example below, but my question still is:

How to interrupt running Basic Macro code, when the main IDE-window does not have focus?

All answers I could find so far (in other threads & this thread) require that one can access the functions of the IDE-window. But what to do if one finds themselves in a situation, where one does not have access to the IDE-functions, because code is putting focus one other objects (= Msgbox in this case).

How to interrupt the code then? In the old VBA days I tend to remember that it was possible with a full keyboard to exit out of code with [Ctrl]+[Pause/Break], or similar.

Below is my quick example on how to programmatically break out, but again, only possible while one has access to the IDE-functions.

Sub EndlessMsgBoxWithCancel
    Do Until False
        If Msgbox( "Continue?", MB_OKCANCEL ) = IDCANCEL ...
(more)
Phrance QueTara gravatar imagePhrance QueTara ( 2021-01-06 20:27:17 +0100 )edit
0

answered 2021-01-06 04:22:09 +0100

Phrance QueTara gravatar image

I figured out a somewhat clumsy way, don't know why or how works:

  • Go into the main LO_Base window, and click Menu/Tool/Macro/Run Macrocs...
  • Then select the exact same Macro you want to interrupt and click the [Run] button
  • Go back into the IDE-window
  • Now, after clicking the [OK] button inside the Msgbox, code halts and lets me stop it.

I'm sure there's a more elegant way than that. LMK.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2021-01-06 04:07:06 +0100

Seen: 37 times

Last updated: Jan 06