Edit and Continue

Ce document est disponible en français


✏️ What it is

Your program is stopped: at a breakpoint, at a Stop statement, or after a step. You read its variables, see what went wrong, and change the code right there. Then you go on: CONT in the REPL, Continue or a step in the debugger. The program picks up where it was, running your edited code, without starting over.

The VBA editor in Office does some of this too. But many edits make it reset the project ("This action will reset your project, proceed anyway?"), and everything the program had built up so far is lost. RD-VBA applies every edit it can apply correctly, which is more than the VBA editor does. When an edit can't be applied, RD-VBA doesn't end your program: it keeps waiting where it is, tells you which edit is in the way and why, and lets you choose. You can take the edit back and go on, or run the program again.

✅ What applies when you go on

Code you're not running right now:

  • The body of a procedure the program isn't in. Its next call runs the new code. This holds for a method of a class too, even while objects of the class are alive.

The procedure you're stopped in, and the procedures that called it:

  • Edit any statement of the procedure you're stopped in. A line you edit above the stop isn't run again. A line you edit, insert or delete below it is run as it is now, when the program gets there.
  • Edit the next line to run, the one marked as the stop (a breakpoint's line, or the line after a Stop), and it runs as edited.
  • In a procedure that called the one you're in, edit the lines after its call. They run as edited when the call returns. Its call line has to stay as it was (see below).
  • Lines can move: an edit that adds or removes lines above the stop is applied, and breakpoints follow the lines they were on.
  • Add a local variable, Dim or Static, to the procedure you're in or to one that called it: it starts at its default, and the others keep their values. A Dim you remove is no longer there for the code, and goes when its procedure returns. A Static you remove waits (see below).

Declarations you add:

  • A procedure, in a module or a class.
  • A module variable (Public or Private), a Const, a Declare.
  • A Type or an Enum, or a member added to an Enum.
  • A field of a class, even while objects of the class are alive: each of them gets it, at its default.

Other changes the program reads afresh:

  • A procedure, variable, Const or Type removed, when nothing the program is running still uses it.
  • The value of a Const or of an Enum member, except one that sizes an array or a fixed-length String * N that already exists, directly or through another Const written in terms of it, and except one a procedure the program is in has already read (see below).
  • The parameters of a procedure the program isn't in, and its callers, which are checked again.
  • A Declare statement changed.
  • An Option line in a module the program isn't in. Option Base waits when that module holds an array declared without a lower bound.

Variables keep their values across every edit that applies. That includes module-level variables, Static variables and the fields of your objects.

🛑 When the program stops at an error

  • An error that nothing handles: fix the line it stopped at and go on, and the line runs as you fixed it. Go on without fixing it, and the line runs again: the error comes back and the program stops there again, as in the VBA editor. Err still holds the error.
  • Set Next Statement (Goto) to another line: the program goes on from there, and the error isn't raised. Err still holds it.
  • An error your code handles (On Error GoTo, with break on all errors): Continue gives it to your handler. Editing the line that raised it waits until you run again, because the handler is already on its way.

⏸️ What waits until you run again

Some edits can't be applied to a program that's already running, because the program holds something the edit would change underneath it. RD-VBA doesn't guess, and never applies half of an edit. When Continue or a step meets one of these, the program is refused and keeps waiting, and the edit is named with its reason. Take the edit back and go on, or run the program again to have it.

You changed… Why it waits
A Type whose values the program may hold, a field added to it or changed in it Those values are laid out already, by the fields the Type had. The Type keeps those fields for as long as the program is in progress: take the edit back and go on, or end the program, and the edit applies. The project's values are reset then, as MS-VBA resets the project for this edit: every variable starts again from its default, and the objects go, as after an End.
A Static removed from a procedure What the procedure stored in it outlives the call: run the program again to have it gone.
A local's type, or a variable's type, while it holds a value The value would have to be converted under the program. A module variable or a Static keeps its value, as it was declared, for as long as the program is in progress: take the edit back and go on with it, or end the program, and the edit applies.
A Const (or Enum member) that sizes an array or a String * N, given another value, directly or through another Const What it sizes exists already, at its old size.
A Const or Enum member that a procedure the program is in reads That procedure read the old value already.
An Option line of a module the program is in The running procedure keeps the setting it started with.
The parameters of a procedure the program is in Its arguments were passed already, by the old parameter list.
The line a calling procedure is in the middle of (its call line) Half of it has run already.
Any edit of a calling procedure whose call is in a condition or a loop header (If F() Then, For i = 1 To F()) The program is in the middle of that line; for now, only a caller on a plain call line takes edits.
The opening or closing line of a block you're inside: a For, a For Each, a With, a Select Case, a Do The loop's counter, the With object or the Select value was made by the old line.
A GoSub the program will return from, or the point a Resume goes back to, when that line itself was edited They point into the code as it was.
What a class Implements, or its Events, while objects of it are alive Those objects are reached through what the class implements.

Code that doesn't compile: a typo, a renamed procedure that something still calls, a variable that isn't declared under Option Explicit. There's no program to go on with until it compiles again. Fix it, and Continue goes on.

👀 Where you see it

In the editor

As soon as you make an edit that won't apply, the editor shows an Information finding: RDC20001 Edit not applied to the waiting program. It sits on the declaration or procedure you edited, where it is now, or, when the code no longer compiles, where it doesn't compile. It says why, and goes away when you take the edit back, or when the program ends.

In the REPL

CONT and STEP say which edits are in the way, each with its reason, and the program keeps waiting:

> 5 Dim Total As Long
> 10 Debug.Print "before"
> 20 Stop
> 30 Debug.Print "after"
> RUN
  before
  BREAK IN 20
  ✅ READY.
> 5 Dim Total As Integer
> CONT
  ⛔ CAN'T CONTINUE
    Edits made while the program waited are not applied to it:
    Program.Main: a local of a procedure the program is in, given another type or made a Static
  RUN to start again.
  ✅ READY.

EDITS lists what's in the way at any time, without trying to go on:

> EDITS
  ⚠️ Edits made while the program waited are not applied to it:
    Program.Main: a local of a procedure the program is in, given another type or made a Static
  RUN to start again.
  ✅ READY.

With nothing in the way, or with no program waiting, it says so:

> EDITS
  No edit is waiting: CONT goes on with every edit made.
  ✅ READY.
> EDITS
  No program is waiting.
  ✅ READY.

In HexIDE's debugger

  • Save the file to have an edit applied. The debugger reads what's saved when you continue, step or set the next statement, and an edit you haven't saved isn't seen.
  • When an edit is in the way, Continue and the steps are refused: the program stays paused, and the debugger's output says which edits, and why.
  • The list of problems doesn't show RDC20001 for a program HexIDE is debugging. The debugger's output carries it there.

⚖️ Compared with the VBA editor

Measured in Excel (64-bit) at a Stop in a procedure, across 44 kinds of edit, and, for the last row, at an error that nothing handles:

Kind of edit VBA editor RD-VBA
A procedure you're not in goes on goes on
Statements of the procedure you're stopped in, above, at or below the stop goes on goes on
Statements of a caller, away from its call line goes on goes on
A caller's call line resets waits, and names the edit
A local added (Dim) goes on goes on
A local removed; a Static added resets goes on
A local retyped, or a Dim made a Static resets waits, and names the edit
A Private module variable, a Const or a Declare added goes on goes on
A Public module variable added resets goes on
A procedure added, in a module or a class resets goes on
A Type or an Enum added, or a member added to an Enum resets goes on
A field added to or changed in a Type the program may hold values of resets waits, and names the edit; the project is reset once the program is over
A Const's value changed resets goes on, unless it sizes what a variable holds, or a running procedure read it (waits)
A procedure's parameters changed, for one you're not in resets goes on
The same, for the one you're in resets waits, and names the edit
A Declare changed; an Option line added or removed resets goes on (an Option line: in a module the program isn't in)
A method body of a class with live objects goes on goes on
A field added to a class with live objects goes on goes on
The line an error stopped at, fixed goes on after it, without running your fix runs as you fixed it

Where the VBA editor resets, it asks first, and Cancel takes the edit back. Where RD-VBA waits, nothing is lost: a variable whose type you changed keeps its value until the program is over. The program stays where it was, and you choose: take the edit back and go on, or run again.

See also


ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca