Ad Space — Top Banner

?RG ERROR

Dragon Data Dragon 32/64

Severity: Minor

What Does This Error Mean?

?RG ERROR means RETURN Without GOSUB — the Dragon executed a RETURN statement but there was no preceding GOSUB to return to. This is almost always caused by the main program code accidentally running into the subroutine section.

Affected Models

  • Dragon 32
  • Dragon 64
  • Dragon 200E
  • XRoar emulator

Common Causes

  • Main program code falls through into the subroutine section instead of stopping
  • A GOTO jumps directly into a subroutine, bypassing the GOSUB
  • A subroutine placed before the main program END/STOP line
  • Nested GOSUB calls with too many RETURN statements

How to Fix It

  1. Add END or STOP before your subroutine section.

    The most common cause: the main program runs line by line and reaches the RETURN of a subroutine. Add END at the last line of the main program so execution stops before reaching the subroutines. Example: 490 END

  2. Never use GOTO to jump directly into a subroutine.

    GOTO 500 when line 500 is the start of a subroutine bypasses the GOSUB stack entry. The RETURN at the end of the subroutine has nowhere to return to — ?RG ERROR results. Always use GOSUB to call subroutines.

  3. Check that every GOSUB has exactly one RETURN.

    List all your GOSUB calls and match each one to the RETURN that ends that subroutine. If you have more RETURNs than GOSUB paths, one RETURN is being executed without a GOSUB.

  4. Place subroutines at the end of your program.

    Standard Dragon BASIC style: main program at low line numbers, END or STOP before the subroutines, then subroutine code at higher line numbers. This prevents accidental fall-through.

Frequently Asked Questions

What is the difference between END and STOP in Dragon BASIC?

Both end program execution. STOP also prints BREAK IN <line number>, which is useful during debugging. END is the normal program terminator. Use STOP when you want to pause and inspect variables during development.

Can I have subroutines before the main program?

Technically yes, but you must start the main program with a GOTO past all the subroutines. For example: 10 GOTO 100 — then subroutines at 20-90, main program from 100 onwards. Most programmers put subroutines at the end to keep the structure clear.