Skip to content

Start here

D/BASIC has a pleasant learning curve because the first rung is genuinely small. Start with output. Add variables. Add a decision. Only then decide whether you need procedures, objects, or a window.

First contact

Open the browser playground, replace the editor contents with this, and choose Run:

10 PRINT "HELLO"
20 PRINT "THE MACHINE IS LISTENING."
30 END

The numbers are real line numbers, not comments. They can be branch targets, but they are optional:

PRINT "HELLO"
PRINT "THE MACHINE IS LISTENING."
END

Both programs have a console face. PRINT, INPUT, and the program's final status belong there. The same face also powers non-interactive scripts; Console, Scripts & GUI explains the distinction.

A program with a little life in it

DEFINT A-Z

DIM Secret, Guess
Secret = 7

PRINT "I AM THINKING OF A NUMBER FROM 1 TO 10."
INPUT "YOUR GUESS"; Guess

IF Guess = Secret THEN
  PRINT "EXACTLY RIGHT."
ELSEIF Guess < Secret THEN
  PRINT "TOO LOW."
ELSE
  PRINT "TOO HIGH."
END IF

DEFINT A-Z makes otherwise-untyped names beginning A through Z into INTEGERs. It is a compact and useful declaration of intent for counters and small whole numbers.

Input needs a provider

An interactive console host pauses for the reply. A non-interactive script host reaches the normal end-of-input refusal instead. Replace the INPUT line with Guess = 5 when you want to study the control flow without mounting an input provider.

Numbered lines and named labels can mix

Porting an old listing does not require a ceremonial rewrite. Modernize the parts you touch.

10 GOSUB Banner
20 FOR Turn% = 1 TO 3
30   PRINT "TURN"; Turn%
40 NEXT Turn%
50 GOTO Finished

Banner:
  PRINT "MIXED-ERA BASIC, ONE PROGRAM"
  RETURN

Finished:
  PRINT "DONE"

Targets may be a line number or a named label. Statements can share a physical line with :, although one statement per line is easier to read and diagnose.

The other face: a window

A window program adds lifecycle handlers. Three handlers are fundamental: open, draw, and close. A program with handlers alone is windowed; a program that also has top-level executable statements can offer both console and window faces from one DBC image.

WINDOW SUB OPEN()
  SERVICE SET_TITLE("First window")
  SERVICE INVALIDATE()
END SUB

WINDOW SUB DRAW()
  INTENT GFX.BEGIN_FRAME()
  INTENT GFX.FILL_RECT(0, 0, 320, 192, 2081)
  INTENT GFX.DRAW_TEXT(12, 14, "HELLO, WINDOW", 3, -1, 2081)
  INTENT GFX.PRESENT()
END SUB

WINDOW SUB CLOSE()
END SUB

The source says what to draw. The host decides how the frame reaches a browser canvas, GPU window, or D/OS composed head. That separation is the heart of D/BASIC portability.

Read Windows & Events before adding keyboard and pointer input. Read Widgets when you would rather compose a button than paint one from primitives.

Desktop command line

The dbasic host tool uses the same compiler and DBC runtime contract:

dbasic run hello.bas
dbasic build hello.bas -o hello.dbc
dbasic exec hello.dbc

For a native window:

dbasic run --native app.bas

run accepts source or DBC and detects the format from the file's bytes. build produces a portable .dbc; exec runs an existing image. See Bytecode & Delivery for Windows, Linux, macOS, browser, and D/OS delivery.

How to read compiler messages

A useful diagnostic answers three questions:

  • Where? A source line and column.
  • What? A normal syntax/type problem or a governed refusal.
  • Why? A human explanation, often with a stable rule identifier.

Do not treat “refused” as a crash. It means the compiler or runtime reached a deliberate boundary—for example an unavailable Intent route, mismatched library, or permanently disallowed machine operation—and stopped without pretending the request worked.

Choose your next chapter


Next: Console, Scripts & GUI →