Your First Program

4.1 Hello, World!

Press F5. A window opens showing the text. END stops the program; QB64-PE then shows "Press any key to continue". END is optional at the end of the main program.

PRINT "Hello, World!"
END

4.2 Anatomy of a BASIC program

One statement per line; use : to put several statements on one line (CLS: PRINT "Hi").

Keywords are case-insensitive; the IDE capitalizes them for you (print becomes PRINT).

Variables need no declaration by default (but you can require it — Chapter 6).

Strings use double quotes. There are no escape sequences inside strings; use CHR$(34) for a quote character.

' hello.bas — my first QB64 program
' A line starting with an apostrophe is a comment (REM also works).
REM This is also a comment.

CLS                              ' clear the screen
PRINT "What is your name";       ' semicolon keeps the cursor on the same line
INPUT userName$                  ' read text into a string variable
PRINT "Hello, "; userName$; "!"  ' print several items
PRINT "Your name has"; LEN(userName$); "letters."
END

4.3 PRINT basics

PRINT "A"; "B"; "C"          ' ABC        (semicolon: no space)
PRINT "A", "B", "C"          ' A    B    C  (comma: next 14-column print zone)
PRINT 1; 2; 3                ' positive numbers print with a leading space and a trailing space
PRINT                        ' blank line
PRINT "No newline";          ' trailing semicolon suppresses the newline
PRINT " — continued"
PRINT 10 / 4, 2 ^ 10, SQR(2)
? "Question mark is shorthand for PRINT"   ' the IDE expands ? to PRINT

4.4 A tiny interactive program

With INPUT "prompt"; var a question mark is added after the prompt; with INPUT "prompt", var it is not.

CLS
INPUT "Enter the width: ", w
INPUT "Enter the height: ", h
PRINT "Area ="; w * h
PRINT "Perimeter ="; 2 * (w + h)

4.5 Dialect notes

Classic BASIC: every line needs a number, and you type RUN to execute: ``basic 10 PRINT "HELLO, WORLD!" 20 END RUN ` FreeBASIC: Print "Hello, World!" — identical. Compile with fbc hello.bas. Keywords are case-insensitive; the convention is Print, Dim, End If. VB.NET: `vbnet Module Program Sub Main() Console.WriteLine("Hello, World!") Dim name As String = Console.ReadLine() Console.WriteLine($"Hello, {name}!") End Sub End Module ``

4.6 Console-only programs in QB64-PE

By default QB64-PE opens a graphics-capable window. For a command-line tool that prints to the terminal:

$CONSOLE (without :ONLY) gives you both a program window and a console; switch output with _DEST _CONSOLE and _DEST 0.

$CONSOLE:ONLY
PRINT "This goes to the terminal (stdout)."