Appearance
First Programs
The quickest way to learn a language is by trying it out yourself. Just a few lines are enough to understand the fundamental principles. In this chapter, you will learn how to declare variables, perform simple calculations, and print results using PRINT. We will also look at common beginner mistakes and how to avoid them.
Declaring Variables
Variables are declared with DIM, constants with CONST. Each variable has a name, a type, and optionally an initial value.
DIM= allocate storage for a variableCONST= constant value that cannot be changed
Example:
vb
PROGRAM
DIM a AS INT = 5
CONST PI AS REAL = 3.14159
PRINT a, PI ' Output: 5 3.14159
END PROGRAMNotes:
- Variable names should be descriptive (
counterinstead ofc). - Constants help avoid magic numbers.
Simple Calculations
The VM supports the usual operators: +, -, *, /, MOD.
Important: Integer operations are saturating.
Example: Addition & saturation
vb
PROGRAM
DIM x AS INT = 32000
DIM y AS INT = 1000
PRINT x + y ' Output: 32767 (saturated)
END PROGRAMExample: Division
vb
PROGRAM
DIM a AS INT = 7
DIM b AS INT = 2
PRINT a / b ' Output: 3 (INT)
PRINT TO_REAL(a) / b ' Output: 3.5 (REAL)
END PROGRAMTip: If you expect fractional values, use REAL or convert using TO_REAL.
PRINT / Debug Output
PRINT outputs values and text. Multiple values are separated by commas.
Example:
vb
PROGRAM
DIM v AS INT = 2
PRINT "v=", v ' Output: v= 2
END PROGRAMMultiple values:
vb
PROGRAM
DIM a AS INT = 1
DIM b AS INT = 2
PRINT "Sum:", a + b ' Output: Sum: 3
END PROGRAMDebugging tip: Use clear prefixes like [DBG] so outputs are easy to spot.
vb
PRINT "[DBG] counter=", counterCommon Beginner Mistakes
| Issue | Cause | Fix |
|---|---|---|
| Program stops immediately | Missing END PROGRAM | Always end scripts with END PROGRAM |
| Division by zero | Denominator = 0 | Check first: IF b <> 0 THEN … |
| Unexpected rounding | Integer division instead of REAL | Use TO_REAL |
| Block used without instance | Block called without DIM | Instantiate first: DIM T AS TON |
| Comment formatting errors | Incorrect ' or REM usage | Always start comments with ' or REM |
Summary
- Declare variables with
DIM, constants withCONST. - Arithmetic works as expected, but saturates.
PRINTis the most important tool for understanding and debugging.- Common mistakes are easy to avoid once you know the rules.