Craft Basic

by Gemino Smothers
Last Updated 10:20 AM 12/19/2023

ReferenceKeywordsFile HelpEdit HelpView HelpProgram HelpSearch HelpMemoryDistributionKnown IssuesButton CodesQuick Examples


Operator precedence:
NOT(), ^, MOD, *, /, +, -, <, >, <=, >=, =, <>, XOR, AND, OR, Functions, (, )

AND may be written as &.
OR may be written as |.
MOD may be writen as %.
XOR may be written as ~.
NOT() may be written as !.
^ is the power operator.

Functions have no precedence over any operators, except parentheses.
Floating point numbers are supported.
The negative operator is supported.
Parentheses may be used to override order of operations.
White space is optional.

Variable names a-z are pre defined.
All other variable names may consist of numbers and letters only.
Define variables by using let varname=0 with 0 as any value.
The define command may be used to bulk let commands together.
Omit the let and use commas to separate the definitions.
Negation of variables is v * -1 and not -v.

Define arrays by using dim arrayname[arraysize].
The arraysize can be a variable, value, or comma separated list.
Arrays are zero indexed and may only be one dimension.

There are artery and unary functions.
Functions have no precedence over any operators except parentheses.

Input may optionally have a prompt with double quotes, comma, variable.
Arrays and functions may be used wherever expressions are used.
Arrays may be used with the input and button commands.
Output may be combined in print, alert, and title using commas.
Output may include numbers, expressions, and double quoted text.
Output may also include the keywords COMMA, QUOTE, TAB, and NEWLINE between commas.

Back to top


PRECISION expression
(short command: PRE)
(set display decimal places)
DEFINE variable=expression,etc...
(short command: DEF)
DIM arrayvariable[variable OR literal number] ARRAYSIZE variable,array
(short command: ARSZ)
(returns the size of an array to a variable)
(short command: ERAR)
(sets the contents of an array to zero)
TITLE expression OR comma OR "TEXT"
IF expression THEN labelname
(if short command: ?)
IF expression THEN
(endif short command: ??)
(else short command: ???)
LET variable=expression
(short command: #)
FOR variable = expression TO expression STEP expression
NEXT variable
(loop from start to finish while stepping index)
BREAK / BREAK variable
(without variable breaks do loop)
(with variable breaks relative for loop)
LOOP expression / LOOPWHILE expression / LOOPUNTIL expression
(loop and loopwhile are the same)
(loop with no parameter for an infinite loop)
PRINT expression OR comma OR "text"
(short command: @)
(use commas to combine outputs)
(use the word comma between commas to display commas)
INPUT "prompt",variable
(short command: IN)
(the prompt is optional)
GOTO labelname
(short command: .)
LABEL labelname
GOSUB subname
(short command: ..)
SUB subname
(short command: ...)
CONFIRM "prompt",variable
(short command: CF)
(returns 1 on yes and 0 or no)
ALERT expression OR comma OR newline OR "text""
(short command: @@)
BUTTON variable,buttoncode
(short command: BTN)
(button code may be accepted as an expression)
LOADIMAGE handlevariable,"filename.bmp"
(short command: LIMG)
(bmp, jpg, or gif)
DRAWIMAGE handlevariable,x,y
(short command: DIMG)
(x and y may be expressions)
FREEIMAGE handlevariable
(short command: FIMG)
PLAYWAVE "filename.wav"
(short command: PWAV)
CURSOR expression,expression
(short command: CR)
RESIZE expression,expression,expression,expression
(resizes the window)
(centers the window)
DOT expression,expression
LINE expression,expression,expression,expression OVAL expression,expression,expression,expression
RECT expression,expression,expression,expression FGCOLOR expression,expression,expression
(short command: FG)
BGCOLOR expression,expression,expression
(short command: BG)
(turn shape fill for graphics primitives on or off)
(short command: WT)
(process windows messages, input, and output)
(prevents freezing during long loops)
(short command: X)
(CLS by itself clears the text output and graphics.)
(Add the GRAPHICS keyword before setting colors, drawing graphics, or creating forms.)
(Only use the GRAPHICS keyword once.)
(drawing transparency. defaults to off)
BUTTONFORM expression, expression, expression, expression
(generate new button form with specified coordinates and size)
(use formid to select the form handle)
(use formtext to prepare the form text)
STATICFORM expression, expression, expression, expression
(generate new static form with specified coordinates and size)
(use formid to select the form handle)
(use formtext to prepare the form text)
(applies formtext to selected formid)
(applies the last set foreground and background colors to the selected formid)
(formid 0 always applies to the text output window)
FORMID expression
(set the id to be used by form commands)
FORMTEXT expression OR comma OR newline OR "TEXT"
(set the text to be used by form commands)
RUN "winprogram.exe",parameters
(the first parameter is the program to run)
(the following parameters are formatted like print and combined)
(stops the program execution)
(required when the program doesn't end with an endless loop)
(also required to prevent execution past subs)
(short command: ')
(function returns milliseconds since boot)
(function returns random number)
(function returns mouse x coordinate relative to window)
(function returns mouse y coordinate relative to window)
(function returns 1 if left mouse button is pressed or 2 for right)
(returns 0 when no mouse button is clicked)
(function returns id of any form that has been clicked)
(returns 0 when no form is clicked)
(function returns absolute value)
(function returns integer by truncation)
(function returns rounded integer)
(>= .5 rounds up and <= .4 rounds down)
(function returns square root)
(function returns sine)
(function returns cosine)
(function returns tangent)
(function returns arctangent)
(function returns logarithm)
(function returns 0 if 0, -1 if negative, and 1 if positive)
(function returns exponential value)
(function returns 1 if prime and 0 if not)
(function returns 1 if factorial and 0 if not)

Back to top

File Help:

Select new from the file menu to begin editing a new file.
Select load from the file menu to load an existing file.
Select save from the file menu to save the file currently being edited.
Select print from the file menu to send the contents of the current file being edited to the printer.

Back to top

Edit Help:

Select undo from the edit menu to reverse the last edit action.
Select a portion of text and then select cut from the edit menu to cut text to the system clipboard.
Select a portion of text and then select copy from the edit menu to copy text to the system clipboard.
Select a portion of text and then select paste from the edit menu to paste text to the system clipboard.
Select all from the edit menu to select all of the text in the current file being edited.

Back to top

View Help:

Select line count from the view menu to count the total lines in the current document being edited.
Select memory limit to view the remaining free bytes.

Back to top

Program Help:

Select run from the program menu to execute the code currently being edited.
Select kill from the program menu to stop code execution.
Select update from the program menu to reload source code from the editor to memory during execution.
Source files may be dragged and dropped or associated with the exe.

Back to top

Search Help:

Select text or subs from the search menu.
For text, type a string and press find next to search the current file being edited for a line containing the string.
Text searches begin where the file is currently being viewed and are not case sensitive.
For subs, select a sub from the list and press find line.

Back to top


Maximum lines of code is 10000.
Maximum operands in an expression is 200.
Maximum variables is 500.
Maximum arrays is 500 with 1000 maximum elements each.
Maximum image handles is 200.

Back to top


Craft Basic may be used as a scripting language by associating .bas files.
If you prefer to distribute the program as an .exe, follow these steps.
First, copy and paste Craft Basic.exe to the distribution directory.
Then copy your programs .bas file to the same directory.
Rename Craft Basic.exe to match the .bas file.
Change the .bas file extension to a .run file.
The result should look like myprogram.exe and
When you run the resulting exe, your program will execute automatically.
Now you may include a readme and zip it up.

Back to top

Known issues:

The expression -2^2 doesn't evaluate correctly unless written as (2^2)*-1.

Window resizing isn't exact and differs on Windows versions. Add extra pixels to compensate.

Want to help fix an issue? Found a new problem?


Back to top

Button Codes:

01 Left mouse button02 Right mouse button03 Control-break processing04 Middle mouse button (three-button mouse)
08 BACKSPACE key09 TAB key10 CLEAR key11 ENTER key
16 SHIFT key17 CTRL key18 ALT key19 PAUSE key
20 CAPS LOCK key27 ESC key32 SPACEBAR33 PAGE UP key
34 PAGE DOWN key35 END key36 HOME key37 LEFT ARROW key
42 (OEM) specific43 EXECUTE key44 PRINT SCREEN key (Win 3.0+)45 INS key
46 DEL key47 HELP key48 0 key49 1 key
50 2 key51 3 key52 4 key53 5 key
54 6 key55 7 key56 8 key57 9 key
65 A key66 B key67 C key68 D key
69 E key70 F key71 G key72 H key
73 I key74 J key75 K key76 L key
77 M key78 N key79 O key80 P key
81 Q key82 R key83 S key84 T key
85 U key86 V key87 W key88 X key
89 Y key90 Z key91 Left Windows key92 Right Windows key
93 Applications key96 Numeric keypad 0 key97 Numeric keypad 1 key98 Numeric keypad 2 key
99 Numeric keypad 3 key100 Numeric keypad 4 key101 Numeric keypad 5 key102 Numeric keypad 6 key
103 Numeric keypad 7 key104 Numeric keypad 8 key105 Numeric keypad 9 key106 Multiply key
107 Add key108 Separator key109 Subtract key110 Decimal key
111 Divide key112 F1 key113 F2 key114 F3 key
115 F4 key116 F5 key117 F6 key118 F7 key
119 F8 key120 F9 key121 F10 key122 F11 key
123 F12 key124 F13 key125 F14 key126 F15 key
127 F16 key128 F17 key129 F18 key130 F19 key
131 F20 key132 F21 key133 F22 key134 F23 key
131 F20 key132 F21 key133 F22 key134 F23 key
135 F24 key144 NUM LOCK key145 SCROLL LOCK key186-192 OEM specific
219-228 OEM specific230 OEM specific246 Attn key247 CrSel key
248 ExSel key249 Erase EOF key250 Play key251 Zoom key
253 PA1 key254 Clear key

Back to top

Quick Examples:






Back to top