Free Basic Command Reference:

#define

Syntax: #define identifier meaning
Type: metacommand

Defines an identifier with a custom meaning, so that by simply defining the idenfier to something different your program can run completely different (i.e. think cross-compatibility, portability).

This command has allowed freebasic to be ported to linux, and potentially new systems.

See also #undef.

Differences:
New to Freebasic.

#else

Type: metacommand

See #if, #ifdef, or #ifndef.

Differences:
New to Freebasic.

#elseif

Type: metacommand

See #if, #ifdef, or #ifndef.

Differences:
New to Freebasic.

#endif

Type: metacommand

See #if, #ifdef, or #ifndef.

Differences:
New to Freebasic.

#if

Syntax: #if (condition)
Type: metacommand

#if is a mechanism to only compile code if a condition is true, and can provide alternative code to compile based on more conditions.

Mainly used for portability between different systems (compile only system specific code), and porting cc++ headers to FreeBasic as it's an essential part of cc++ libraries.

Syntax:

#if (condition)
 ...
[#elseif (condition)
 ...]
[#else
 ...]
#endif



If the condition for the #if statement is true then the following code is executed, and then skips past the #endif block. If it was false then the same happens to the #elseif statement, until #else. If no condition was true down to the #else statement then the following code is executed.

See also #ifdef, #ifndef, if...then.

Differences:
New to FreeBasic.

#ifdef

Syntax: #ifdef symbol
Type: metacommand

This is a shortcut to:

#if defined(symbol)



Shortened, it is coded like so:

#ifdef symbol



Saving you the typer 6 characters.

See also #ifndef, #if.

Differences:
New to Freebasic.

#ifndef

Syntax: #ifndef symbol
Type: metacommand

This is a shortcut to:

#if not defined(symbol)



Shortened, it is coded like so:

#ifndef symbol



Saving you the typer 9 characters.

See also #ifdef, #if.

Differences:
New to Freebasic.

#undef

Syntax: #undef identifier
Type: metacommand

Undefines a symbol previously defined with #define.

Differences:
New to Freebasic.

$DYNAMIC

Syntax: '$DYNAMIC
Type: metacommand
Category: memory

$DYNAMIC is a metacommand which affects the way arrays are handled with memory.

Makes all arrays declared to be dynamic, in that they may be declared to a variable size, and can change in size in runtime.

e.g.


'$dynamic
dim a(100)
erase a
redim a(200)

$inclib

Syntax: '$inclib: "name"
Type: metacommand

Includes a library (.a file) in the linking process, making it easier for the user to compile, since the user doesn't have to explicitly type at the command line: "fbc sourcefile -a libfile".

e.g. (incomplete code snipet)


'$inclib: "mylib" 'this will include libmylib.a in the link process

Differences:
New to FreeBasic.

$include

Syntax: '$include 'file'
Type: metacommand

Include makes the file given act asif it was placed in code at the point where include was called. This is useful to remove code from a file and seperate it into more files.

This makes the compiler stop compiling the current file and start compiling the include file. Once the compiler has reached the end of the include file, the original source file continues to be compiled.

You may include files within an include file, although avoid including the original file into itself, this will not produce valid results.

The standard include file is ends in .bi, and is mainly for declaring subs/functions/variables of a library.

Differences:
Between QB:
if path/name has an underscore char, use quotes instead of apostrophe.

$static

Syntax: '$static
Type: metacommand

'$static makes all arrays declared to have set memory space upon compile time. This means arrays cannot be redeclared (with redim) or erased (with erase).

See also static.

ABS

Syntax: ABS (number)
Type: function
Category: math

ABS returns the positive number of the number given.

e.g:


'returns 1, 3.1415, and 42
print abs(-1), abs(-3.1415), abs(42)

ACCESS

Syntax: ACCESS {read | write | read write}
Type: clause
Category: files

ACCESS is used with the open statement.

This example shows how to open the file "data.raw" with read access, in binary mode, in file slot 1.


open "data.raw" for binary access read as 1

acos

Type: function
Category: math

See also atn.

Differences:
New to FreeBasic.

ALIAS

Type: clause

ALIAS gives a procedure in a library a new name that you want to reference it with.

For example if there is a sub called xClearScreen and you want to reference it with the name ClearVideoScreen, here is sample code to do so:


declare sub xClearScreen alias "ClearVideoScreen" ()

allocate

Syntax: (function( byval bytes as integer ) as any ptr)
Type: function

Allocates as much memory as you want (in bytes) and returns a pointer to the beginning. This allows for flexible and dynamic arrays that can be created and destroyed.

e.g. of a dynamic array using allocate and pointers to access an array and calculate the mean average of all values:


dim a as integer ptr

'allocate space
input "number of values"; n
a = allocate(len(integer) * n)
if a = 0 then
print "memory error, cannot allocate space!"
sleep
end
end if

'read in values
for i = 1 to n
print "value #"; str$(i); ": ";
input a[i-1]
next

'process values
total = 0
for i = 0 to n - 1
total = total + a[i]
next
print "mean average: "; total / n

'deallocate space
deallocate(a)

print ""
sleep



See also deallocate.

Differences:
New to FreeBasic.

AND

Syntax: number1 AND number2
Type: operator
Category: logic

Bitwise comparison which compares bits in two numbers and sets the corresponding bit in the result to 1 if both bits are 1, otherwise sets the bit in the result to 0.

Example with (&b0110 AND &b0101)

0110
0101
----
0100



result: &b0110

ANY

Type: clause

Used to disable type checking for a variable that is a parameter of a procedure.

Example:
(this code has not been verified to work)


dim x as integer
x = 15
echo x
sub echo (a as any)
print a
end sub

APPEND

Type: keyword
Category: file mode

The APPEND keyword is used with the OPEN statement which opens the file with the APPEND file mode. This means that the file is opened with sequential access and starts reading/writing at the end of the file.

See this external resource for examples and more info: http://www.petesqbsite.com/sections/express/issue4/index.html#filemanip.

See also open, PRINT #, WRITE (File I/O), random.

AS

Type: clause

AS is a language construct with many uses which vary where you use it.

Specify variable type in a list with:
sub
declare sub
function
declare function
common
dim
redim
shared
static

Specify variable type within a user defined type with type

Set the file slot number for the file to be opened in with open.

Specify a field name in a random-access record with field

Differences:
Between QB:
AS is no longer used with the command name. See details of name for more information.

ASC

Syntax: ASC(string) as integer
Type: function

Returns the ascii code of the first character in the string. This has the opposite effect of chr$.

e.g.

print "the ascii code of 'a' is:"; asc("a")


Will return "the ascii code of 'a' is: 97".

asin

Type: function
Category: math

See also atn, acos.

asm

Allows the use of inline assembly (machine code) used.

Syntax:

asm
 ... 'asm code
end asm



e.g. multiplying two integers with asm.


declare function mulintegers( byval x as integer, byval y as integer ) as integer

randomize timer
a = rnd * 100
b = rnd * 100

print a; " * "; b; " = "; mulintegers( a, b )

sleep


'':::::
function mulintegers( byval x as integer, byval y as integer ) as integer
dim res as integer

asm
mov eax, dword ptr [x]
imul eax, dword ptr [y]
mov dword ptr [res], eax
end asm

mulintegers = res

end function

Differences:
New to FreeBasic

atan2

Type: function
Category: math

See also atn, acos, asin.

ATN

Syntax: ATN(number)
Type: function
Category: math

Returns the arc tangent (or anti-tangent) of the number given. This is the opposite of tan (tangent).

BEEP

Syntax: BEEP
Type: statement
Category: Misc

BEEP tells the system to sound a beep noise.

Example:


beep

Differences:
Between QB: In Qb this was a single tone noise generated through the pc speaker. Now this may not be the case.

bin$

Syntax: bin$ (number)
Type: function

Returns the binary value of a decimal number from integer form to a string. Binary values contain 0's and 1's.

e.g.


print bin$(54321)



will return "1101010000110001".

See also hex$, oct$.

Differences:
New to FreeBasic.

BINARY

Type: keyword
Category: file mode

The BINARY keyword is used with the OPEN statement which opens the file with the binary file mode. Binary mode lets you read/write at any position (in bytes) to any value (using GET and PUT). Binary mode is simply unrestricted raw file access, the most flexible file mode.

Data is read in binary mode using get (file i/o), and written with put (file i/o).

See also open, PUT (File I/O), get (File I/O), random, append, output, input (file mode).

BLOAD

Syntax: BLOAD filename[, addr]
Type: statement

Statement to load a block of binary data from a file.

'filename' is the name of the file to load data from.
'addr' is Address where to load data. If omitted or 0 (NULL), data is loaded on the current work page.

BLOAD can be used to save a block of binary data, and can be also used to load raw pixel data to the screen: if you don't specify the addr argument, or you set it to 0, the data will be treated as pixel data and loaded into the
current work page.

BLOAD "image.bsv", 0



is infact equivalent to:


SCREENLOCK
BLOAD "image.bsv", SCREENPTR
SCREENUNLOCK



Pay attention that the pixel data stored in the file is in the same pixel format as the one used by the current video mode; see Internal pixel formats for details.

See also bsave.

Differences:
Between QB:
Supports blocks of data with sizes bigger than 64K.

BSAVE

Syntax: BSAVE filename, addr, size
Type: statement

Statement to save a block of binary data into a file.

'filename' is the name of the file where data will be saved.
'addr' is the address where to save data from. If 0 (NULL), data is taken from current work page.
'size' is the size of the data block to be saved, in bytes.

BSAVE saves a block of binary data into a specified file. It can also be used to save pixel data from current work page into a file, by specifying 0 as addr argument:

BSAVE "image.bsv", 0, 64000



is infact equivalent to:


SCREENLOCK
BSAVE "image.bsv", SCREENPTR, 64000
SCREENUNLOCK



When saving pixel data, the data will be saved in the current gfx mode pixel format; see Internal pixel formats for details. Also keep in mind a pixel may require more than one byte, so the size argument will need to be adjusted accordingly.

See also bload.

Differences:
Between QB:
Files saved using the FB version of BSAVE are incompatible with files saved using the QB BSAVE.

byref

See also byval.

Differences:
New to FreeBasic.

byte

Type: data type

8-bit signed whole-number data type.

See also ubyte, data types.

Differences:
New to FreeBasic.

BYVAL

Type: clause

BYVAL in a parameter list of a declare statement causes the variable to be passed to the procedure (either sub or function) by its value rather than the usual way by sending the address to the value.

This means that if you pass say the value of the variable 'x' then x cannot be modified in anyway, where as if you send the address the procedure could modify the value of 'x' to anything.

Opposite of byref.
See also declare.

CALL

Syntax: CALL subname ([parameter list])
Type: statement

Calls a sub like in this code snipet:

call foobar (35, 42)



This is old syntax compadibile from the oldest basic dialects. This can be better coded like so:

foobar 35, 42



See also declare, calls, sub.

Differences:
Between QB:
Function must have been declared already.

CALLOCATE

same as ALLOCATE, but clears the contents.

Differences:
New to FreeBasic.

calls

Type: statement

Redundant, and the same as call. Kept for compadibility reasons.

Differences:
Between QB:
Function must have be declared already.

CASE

Type: keyword
Category: control flow

See select case.

CBYTE

Type: function

Converts any numeric expression to a byte.

e.g. this will try convert 260 into 8-bits.


dim x as integer
print cbyte(260)

Differences:
New to FreeBasic.

CDBL

Type: function

Converts any numeric expression to a double-precision number.

cDbl can be explained like so: C-DBL, C (convert) Dbl (double).

CDECL

Syntax: declare {function | sub} procName cdecl alias
Type: calling convention

Stands for C-Declare, which when used with a declare statement passes the variables from right to left (cc++ convention), rather than left to right (fb convention).

e.g. declaring 'pixelColor' from the SDL library.


declare function pixelColor cdecl alias "pixelColor" (byval dst as SDL_Surface ptr, byval x as Sint16, byval y as Sint16, byval color as Uint32) as integer

----------------
I've no clue how VB will "mangle" the imported names, try adding ALIAS "AddNumbers@8" to the VB prototype, or declare it as CDECL at the FB side and as ALIAS "_AddNumbers" at VB.

---------------
See also declare, pascal, stdcall.

Differences:
New to FreeBasic.

CHAIN

Type: statement

Runs another program and transfers control to that program. After called program has ended the original program will gain the control again.

See also run.

Differences:
Between QB:
Calling process will continue running after called process finish, rather than not (like in qb).

CHDIR

Syntax: chdir pathspec
Type: statement
Category: File

Changes the current directory.

If in windows or dos, this changes the current directory on the given drive but does not change the default drive. You must change (v1c, not finished)

CHR$

Syntax: CHR$(byte)
Type: function

Returns the ascii character of the byte given, returned in a single-character string format.

This is useful for accessing symbol's not on the keyboard.

CINT

Type: function

Converts any number to an integer by removing the fractional part.

See also int.

CIRCLE

Syntax: CIRCLE [STEP] (x,y), radius[, [color][, [start][, [end][, [aspect][, F]]]]]
Type: statement
Category: Gfx

Statement to draw circles, ellipses or arcs.

The 'STEP' option specify that x and y are offsets relative to the current graphics cursor position.

'x' and 'y' are coordinates of the center of the circle/ellipse.

'radius' is simply the radius of the circle (or major axis radius of an ellise).

'color' is the color attribute. This is mode specific, see COLOR and SCREEN (graphics) for details.

'start' and 'end' are angles are in radians. These can range -2PI to 2PI; if you specify a negative angle, its value is changed sign and a line is drawn from the center up to that point in the arc. End angle can be less than start angle. If you do not specify start and end, a full circle/ellipse is drawn; if you you specify start but not end, end is assumed to be 2PI; if you specify end but not start, start is assumed to be 0.

'aspect' is the aspect ratio, or the ratio of the y radius over the x radius. The default value is the value required to draw a perfect circle on the screen, keeping pixel aspect ratio in mind.

So this value can be calculated as follows:

ratio = (y_radius / x_radius) * pixel_aspect_ratio



Where pixel_aspect_ratio is the ratio of the current mode width over the current mode height, assuming a 4:3 standard monitor. If aspect ratio is less than 1, radius is the x radius; if aspect is more or equal to 1, radius is the y radius.

'f' is the fill flag. If you specify this flag, the circle/ellipse will be filled with the selected color. This has no effect if you're drawing an arc.

Use this function to draw circles, ellipses or arcs. Custom coordinates system set up by WINDOW and/or VIEW (graphics) affect the drawing operation; clipping set by VIEW also applies. When CIRCLE finishes drawing, the current graphics cursor position is set to the supplied center.

e.g.


' Set 640x480 mode and draws a circle in the center
SCREEN 18
CIRCLE (320, 240), 200, 15
' Draws a filled ellipse
CIRCLE (320, 240), 200, 2, , , 0.2, F
' Draws a small arc
CIRCLE (320, 240), 200, 4, 0.83, 1.67, 3



See also screen (graphics), color.

Differences:
Between QB:
As this function uses a different algorithm from the one used in QB, circles, ellipses and arcs may not be equal pixel-by-pixel to those produced by QB. In addition, this version supports filled circles/ellipses via the F flag, whereas QB doesn't.

CLEAR

Syntax: clear pointer, value, bytecount
Type: statement

Resets all values in an array to what you want (usually 0 is useful).

e.g.


dim array(1 to 100) as integer
clear byref Array(1), 0, len(Array(1)) * ubound(Array)



See also dim.

CLNG

Type: function

Converts any number to a long number. The name can be explained by c-lng (c for convert, lng for long).

CLOSE

Type: statement

Closes one file (in a given file slot #) or closes all files (with no parameter given).

CLS

Syntax: CLS
Type: statement
Category: Console

Clears the console screen.

Differences:
Between QB:
There's no optional argument, the whole screen is cleared.

color

Syntax: COLOR [foreground][,background]
Type: statement
Category: Gfx

Sets the display foreground / background color that is used with console output and graphics output of text.

The COLOR statement sets the current foreground and/or background colors. CIRCLE, DRAW, LINE (graphics), CLS, PAINT, PRINT and PSET all use the last colors set by this function when you don't specify a color to them, where applicable. The color values COLOR accepts depend on the current gfx mode.

Mode 1:
	foreground is screen color (ranging 0-15).
	background modulo 4 is the emulated CGA palette to be used:
		0:	green, red, and brown.
		1:	cyan, magenta and white.
		2:	same as 0, but with bright colors.
		3:	same as 1, but with bright colors.
Modes 2 and 11:
	foreground is a color index in current palette (ranging 0-1).
	background is a color index in current palette (ranging 0-1).
Modes 7 and 8:
	foreground is a color index in current palette (ranging 0-15).
	background is screen color index in current palette (ranging 0-15).
Mode 9:
	foreground is a color index in current palette (ranging 0-63).
	background is screen color index in current palette (ranging 0-63).
Mode 12:
	foreground is a color index in current palette (ranging 0-15).
	background is a color index in current palette (ranging 0-15).
Modes 13 and up:
	foreground is a color index in current palette (ranging 0-255).
	background is a color index in current palette (ranging 0-255).



If you are using a color depth higher than 8bpp, foreground and background are direct RGB color values in the form &hRRGGBB, where RR, GG and BB are the red, green and blue components ranging &h00-&hFF (0-255 in decimal notation). While in hi/truecolor modes, you can also use the RGB function to obtain a valid color value.

e.g.


' Sets 800x600 in 32bpp color depth
SCREEN 19, 32
' Sets orange foreground and dark blue background color
COLOR &hFF8000, &h000040
' Say hello
CLS
LOCATE 19, 44: PRINT "Hello World!"
SLEEP



See also screen (graphics), palette.

Differences:
Betweeen QB:
Foreground range: 0..15, background range: 0..7; there's no border argument.
FB version accepts direct color values in hi/truecolor modes; COLOR in screen mode 1 accepts 4 different CGA palettes instead of the 2 supported by QB.

COMMAND$

Type: function

Returns command line parameters used to call the program.

COMMON

Type: statement

Shares variables between modules.

No example as of now.

See also dim, sub, function.

Differences:
Between QB:
Arrays are ALWAYS dynamic; no sharing between processes.

CONST

Type: statement

Creates symbols which act as a constant (a integer/decimal number or string).

e.g. to make the symbol 'red' to 4 and 'blue' to 1 you would do:

const red = 4, blue = 1



Or to create a string constant:

const msg = "Hello world!"

continue

Syntax: continue {do | for | while}
Type: statement

Re-enters a code block such as a do...loop, for...next, or a while...wend block.

e.g. the second and third print command will not be seen. (Warning, infinite loop - press ctrl+break to exit!)


do
print "i will always be shown"
continue do
print "i will never be shown"
loop
print "neither will I"



See also exit.

Differences:
New to FreeBasic.

COS

Syntax: COS (angle as single)
Type: function
Category: math

Returns the cosine of the angle (given in radians).

CSHORT

Converts any numeric expression to a short integer (16-bit).

No example.

Differences:
New to FreeBasic.

CSIGN

Syntax: csign (unsigned number)
Type: function

Converts an unsigned number to a signed number, in the same sized data type.

Only useful to force signed behaviour of division or multiplication (including with shl and shr).


dim a as ushort
a = 65000
print csign(a) 10



This is the opposite of cunsg.

Differences:
New to FreeBasic.

CSNG

Type: function

Converts any number to a single-precision number.

CSRLIN

Type: function
Category: Console

Returns the current line position (row) of the cursor.

The name can be explained by csr-lin (csr for cursor, lin for line).

CUNSG

Syntax: cunsg (signed number)
Type: function

Converts a signed number to an unsigned number, in the same sized data type.

Only useful to force unsigned behaviour of division or multiplication (including with shl and shr).

e.g.


dim a as short
a = -200
print cunsg(a) 10



This is the opposite of csign.

Differences:
New to FreeBasic.

curdir$

Syntax: curdir$
Type: function
Category: file

Returns the current directory/folder.

e.g.


print curdir$



See also open, dir$, mkdir, rmdir.

Differences:
New to FreeBasic.

CVD

Syntax: CVD(8-byte-string)
Type: function

Converts an 8-byte-string created with MKD$ back to a double-precision number.

CVI

Syntax: CVI(2-byte-string)
Type: function

Converts a 2-byte-string created with MKI$ back to an integer.

CVL

Syntax: CVL(4-byte-string)
Type: function

Converts a 4-byte-string created with MKL$ back to a
long integer.

CVS

Syntax: CVS(4-byte-string)
Type: function

Converts a 4-byte-string created with MKS$ back to a single-precision number.

data

Syntax: data constant [,constant]...
Type: statement

stores data within the program, basicly having file storage within the end executable file. Data can only store constants (integer/decimal number or string).

An example of storing 10 pieces of data:


data 105, 98, 85, 99, 110, 115, 109, 89, 104, 102



To access the data you use the command read. An example of reading 10 pieces of data:


dim height(1 to 10) as integer
for a = 1 to 10
read height(a)
next



See also read, restore.

Differences:
Between QB:
string value MUST be quote'd; Const's are evaluated before storing.

Empty null data items are not supported (asin DATA 1, 3, 2,, 5).

DATE$

Type: keyword

Used to return the current date, or set a new date for the system.

e.g. to get the current date:

print date$



See also setdate, time$, timer.

Differences:
Between QB:
To set the date, you must use SETDATE now.

deallocate

Syntax: (sub( byval src as any ptr ))
Type: statement

Deallocates memory allocated with allocate. See allocate for more details.

Differences:
New to FreeBasic.

DECLARE

Syntax: declare {sub | function} name [lib "mydll"][alias "AddNumbers"] ([parameter [, parameter]...]) [as return_type]
Type: statement

This informs the compiler (and developers) that a function or sub exists and contains all details it needs for calling, the number of parameters and their data type, and the return type.

It is useful to seperate declare statements into include files, though they can simply be at the top of your BAS source file.

It is required however for the declare statement to be before the sub/function itself (unless the sub/function is in a library which will be documented later).

e.g. using declare:


declare function twice (x as integer) as integer
function twice (x as integer) as integer
twice = x * 2
end function

print "twice of 42 is: "; twice(42)



See also sub, function, dim.

defbyte

Syntax: defbyte letterrange[, letterrange]...
Type: statement

Defbyte is used to default variables to a byte number that start with a letter in the range given.
For the syntax, letterrange is in the form of letter-letter, or just letter.

for example:


defbyte b
dim bNumber



this will make 'bNumber' a byte number since it's first letter starts with b.

See also defdbl, defint, deflng, defshort, defsng, defstr, defubyte, defuint, defushort.

Differences:
New to FreeBasic.

DEFDBL

Syntax: DEFDBL letterrange[, letterrange]...
Type: statement

Defdbl is used to default variables to a double-precision decimal number that start with a letter in the range given.
For the syntax, letterrange is in the form of letter-letter, or just letter.

for example:


defdbl a-d
dim a



this will make 'a' a double-precision decimal number since it is in the range of a-d.

See also defbyte, defint, deflng, defshort, defsng, defstr, defubyte, defuint, defushort.

defined

Syntax: defined (symbol name)
Type: function
Category: pre-processor

Given the symbol name, defined() returns true if the symbol has been defined - or false if the symbol is unknown of.

This is used mainly with #if, and possibly with if...then.

Similar to #ifdef except it allows more than one check to occur because of its flexibility.

e.g. - which symbols are defined out of a, b, c, and d ?


const a = 300
#define b 12
dim c as single

#if defined(a)
print "a is defined"
#endif
#if defined(b)
print "b is defined"
#endif
#if defined(c)
print "c is defined"
#endif
#if defined(d)
print "d is defined"
#endif



See also #define, #if.

Differences:
New to FreeBasic.

DEFINT

Syntax: DEFINT letterrange[, letterrange]...
Type: statement

Defint is used to default variables to a integer number that start with a letter in the range given.
For the syntax, letterrange is in the form of letter-letter, or just letter.

for example:


defint i
dim iNumber



this will make 'iNumber' an integer number since it's first letter starts with i.

See also defbyte, defdbl, deflng, defshort, defsng, defstr, defubyte, defuint, defushort, integer.

DEFLNG

Type: statement

Deflng is used to default variables to a long integer number that start with a letter in the range given.
For the syntax, letterrange is in the form of letter-letter, or just letter.

for example:


deflng l
dim lNumber



this will make 'lNumber' a long integer number since it starts with l.

See also defbyte, defdbl, defint, defshort, defsng, defstr, defubyte, defuint, defushort.

defshort

Syntax: defshort letterrange[, letterrange]...
Type: statement

Defshort is used to default variables to a short number that start with a letter in the range given.
For the syntax, letterrange is in the form of letter-letter, or just letter.

for example:


defshort s
dim sNumber



this will make 'sNumber' a short number since it's first letter starts with s.

See also defbyte, defdbl, defint, deflng, defsng, defstr, defubyte, defuint, defushort.

Differences:
New to FreeBasic.

DEFSNG

Type: statement

Defsng is used to default variables to a single-precision decimal number that start with a letter in the range given.
For the syntax, letterrange is in the form of letter-letter, or just letter.

for example:


defsng s-z
dim sNumber, yNumber



this will make 'sNumber' and 'yNumber' a single-precision decimal number since it is in the range of s-z.

See also defint, defdbl, deflng, defstr, single.

DEFSTR

Type: statement

Defstr is used to default variables to a string that start with a letter in the range given.
For the syntax, letterrange is in the form of letter-letter, or just letter.

for example:


defstr s
dim sMessage



this will make 'sMessage' a string since it starts with s.

See also defint, defsng, deflng, defdbl, double.

defubyte

Syntax: defubyte letterrange[, letterrange]...
Type: statement

Defubyte is used to default variables to a ubyte number that start with a letter in the range given.
For the syntax, letterrange is in the form of letter-letter, or just letter.

for example:


defubyte u
dim uNumber



this will make 'uNumber' a ubyte number since it's first letter starts with u.

See also defint.

Differences:
New to FreeBasic.

defuint

Syntax: defuint letterrange[, letterrange]...
Type: statement

Defuint is used to default variables to a uinteger number that start with a letter in the range given.
For the syntax, letterrange is in the form of letter-letter, or just letter.

for example:


defint u
dim uNumber



this will make 'uNumber' a uinteger number since it's first letter starts with u.

See also defint.

Differences:
New to FreeBasic.

defushort

Syntax: defushort letterrange[, letterrange]...
Type: statement

Defushort is used to default variables to a ushort number that start with a letter in the range given.
For the syntax, letterrange is in the form of letter-letter, or just letter.

for example:


defushort u
dim uNumber



this will make 'uNumber' a ushort number since it's first letter starts with u.

See also defint.

Differences:
New to FreeBasic.

dim

Syntax: dim var as type[, var as type]...
Type: statement

Declares data with a set size and type.
This can declare single variables, or arrays (many variables with the same name referenced with an index).

Single variables are declared simply like so:


dim i as integer, s as single



Now imagine you wanted to store 100 numbers of your height over every day of the year. Perhaps 1000 numbers. Using dim to declare 100-1000 numbers will be rediculous, and this is what arrays are for. To dim 1000 numbers under one variable (I will call this 'height') it is simply done like so:

dim height(1 to 1000) as integer



That allows the index to start at 1 and finish at 1000, giving the variable 'height' 1000 slots of data. This can be alternatively coded like so:

dim height(999) as integer



That will give 'height' 1000 data slots, ranging from 0 to 999 (the default starting value is 0).

See data types.

Differences:
Between QB:
if using non-constants as indexes, use REDIM or $DYNAMIC first. (This may change in the future).

dir$

Syntax: dir$ (filespec$, attrib as integer)
Type: function
Category: file

Returns files in the current directory/folder. Results can be filtered with a filespec (more later) and with a matching file attribute.

'attrib' is a combination of the following attributes:
1 - read only
2 - hidden
4 - system
16 - directories
32 - archive

e.g. to list all directories and archive files:


const attrib_readonly = 1
const attrib_hidden = 2
const attrib_system = 4
const attrib_directory = 16
const attrib_archive = 32

sub list_files (filespec$, attrib)
dim filename as string

filename = dir$(filespec$, attrib)
do
print space$(4); filename
filename = dir$("", attrib)
loop while filename <> ""
end sub

print "directories:"
list_files "*", attrib_directory

print "archive files:"
list_files "*", attrib_archive



See also open, curdir$, mkdir, rmdir, files.

Differences:
Between QB:
New addition to FreeBasic.

DO...LOOP

Type: statement
Category: control flow

Repeats a block of statements until/while a contition is met.

Syntax 1:

do [{until | while} condition]
loop



Syntax 2:

do
loop [{until | while} condition]



for example:


dim a as integer
a = 1
do
print "hello"
a = a + 1
loop until a > 10


This will continue to print "hello" on the screen until the condition (a > 10) is met.

See also for...next, while...wend.

DOUBLE

Type: data type

Double is a 64-bit, floating point data type used to store precise decimal numbers. They are similar to single data types but more precise.

However precise double's are, they still have limited accuracy and this can amount to huge losses in accuracy if not used properly.

Example of using a double variable.


dim a as double
a = 1.985766472453
print a



See also data types.

DRAW

Syntax: Draw cmds$
Type: statement
Category: Gfx

Statement for sequenced pixel plotting.

The DRAW statement can be used to issue several drawing commands all at once; it is useful to quickly draw figures. The command string accepts the following commands:

Commands to plot pixels:
	B		Optional prefix; move but do not draw.
	N		Optional prefix; draw but do not move.
	Mx,y		Move to specified screen location; if + or - precedes
			x, movement is relative to current cursor position.
	U[n]		Move n units up. If n is omitted, 1 is assumed.
	D[n]		Move n units down. If n is omitted, 1 is assumed.
	L[n]		Move n units left. If n is omitted, 1 is assumed.
	R[n]		Move n units right. If n is omitted, 1 is assumed.
	E[n]		Move n units up and right. If n is omitted, 1 is
			assumed.
	F[n]		Move n units down and right. If n is omitted, 1 is
			assumed.
	G[n]		Move n units down and left. If n is omitted, 1 is
			assumed.
	H[n]		Move n units up and left. If n is omitted, 1 is
			assumed.
Commands to color:
	Cn		Changes current foreground color to n.
	Pp,b		Flood fills region with border color b with color p.
Commands to scale and rotate:
	Sn		Sets the current unit length; default is 4 pixels per
			unit.
	An		Rotate n*90 degrees (n ranges 0-3).
	TAn		Rotate n degrees (n ranges 0-359).
Extra commands:
	Xp		Executes commands a address p. For example, you can do:
			down10$ = "D10" : DRAW "U10R5X" + VARPTR(down10$) + "L5"

ELSE

Type: conditional

see if...then.

ELSEIF

Type: keyword
Category: conditional

see if...then.

end

Syntax: END [sub | function | if | select | type | enum | return value as integer]
Type: statement

This will end the program or end a code block.

If used with the parameter sub, function, if, select , type, or enum it will end that code block respectively.

If used with no parameter it will end the program and return to the OS.

If used with an integer value it will end the program and return that value to the OS. This is like the C 'return 0;' feature.

If a parameter is given then this end's a block definition (sub, function, if, select, type, or enumeration block).

Differences:
Between QB:
supports returning an integer result to OS

ENDIF

Type: keyword
Category: conditional

See also if...then.

enum

Type: statement

Syntax:
enum listname
item1 [= integer value]
item2 [= integer value]
item3 [= integer value]
...
end enum

enum (short for enumeration) creates a numbered list with items that correspond to discrete values.

(v1c, im too lazy..)

Differences:
New to FreeBasic.

environ

Type: statement
Category: Misc

See setenviron.

Differences:
Between QB:
called setenviron now.

ENVIRON$

Syntax: environ$(var_name$) as string
Type: function
Category: Misc

Returns the value of a system environment variable.

E.g. to show the system variable "path":


print environ$("path")



See also Setenviron, shell.

EOF

Syntax: EOF(f)
Type: function

EOF stands for end-of-file and returns true if any given file open for reading is at the end (no more data can be read from the file, there is no more).

This allows one to read all data from a file, and know when all the data has been read.

e.g.


f = freefile 'find a free file slot
open "file.ext" for input as #f 'open "file.ext" for reading (input mode)
do until eof(f) 'keep reading unless we've read everything
input #f, txt$ 'read a line of text into the variable "txt$"
print txt$ 'show the data on the screen
loop 'repeat
close #f 'close the file slot



See also LOF.

EQV

Syntax: a EQV b
Type: operator
Category: logic

A bitwise operator which compares each bit in the two numbers and returns true for each bit where the coresponding bits in both inputs are true.

i.e.

&b00110011 EQV &b01010101


will return &b00010001.

See also Logical operators.

ERASE

Syntax: Erase array [, array...]
Type: statement

Erases dynamic arrays from memory, or clears all elements in a static array.

err

Type: function
Category: Error

After an error, returns the error code that occured.

Differences:
Between QB:
error numbers are not the same as in QB.

error

Type: statement
Category: Error

Pretends an error has occured. This can be used to simulate custom error numbers.

e.g. to send an error alert of error 150 (just some arbitrary error code) one would do the following:

error 150



See also err.

Differences:
Between QB:
error numbers are not the same as in QB.

exec

Syntax: (function( program as string, arguments as string ) as integer)
Type: function

Differences:
New to FreeBasic.

exepath

Syntax: exepath as string
Type: function

Returns the path of the progam itself. Usually the same as curdir$.

e.g.


a$ = exepath
print "The exe path is: "; a$

Differences:
New to FreeBasic.

EXIT

Syntax: exit {sub | function | do | for | while}
Type: statement
Category: control flow

Leaves a code block such as a sub, function, do...loop, while...wend, or a for...next block.

e.g. the print command will not be seen


do
exit do
print "i will never be shown"
loop



See also exit.

EXP

Syntax: EXP(a)
Type: function
Category: math

Returns e to the power of a number given.
e.g. EXP(5) returns e ^ 5.
e is a constant that is roughly 2.718. In theory it has infinite precision but is approximated on computers for a practical sense.

FIX

Syntax: fix(a) as integer
Type: function

If the input is an integer fix will return the integer, otherwise fix will return the next integer closer to zero. For example fix(1.9) will return 1, and fix(-1.9) will return -1.

This is similar to int(), however int(-1.9) will return -2. With positive numbers there is no change.

See also int, cint.

flip

Category: gfx

Alias for PCOPY and SCREENCOPY. See SCREENCOPY for details.

Differences:
New to QB.

FOR...NEXT

Syntax: for var = value1 to value2 [step value3]
Type: statement
Category: control flow

Repeats execution of a code block a number of times, with a counter increasing/decreasing signifying which iteration the for loop is at.

e.g. to print a triangle of stars:


height = 10
for i = 1 to height
print string$(i, "*")
next



Output:

*
**
***
****
*****
******
*******
********
*********
**********



Example of a counter:


dim i as single
print "counting from 3 to 0, with a step of -0.2"
for i = 3 to 0 step -0.2
print "i is "; i
next



See also do...loop.

Differences:
Between QB:
doesn't support implicit pointers (ie: byref vars) as counters.

e.g.


sub foo( a as integer )
for a = 1 to 100
next a
end sub



'a' is an implicit pointer, and this is not supported.

FRE

Syntax: fre
Type: function
Category: Misc

Returns the free memory (ram) avaliable in bytes.


mem = fre
print "Free memory:"
print
print mem; " bytes"
print mem 1024; " kilobytes"
print mem (1024 * 1024); " megabytes"



See also dim, allocate.

Differences:
Between QB:
value doesn't matter, always returns the free physical mem available.

FREEFILE

Syntax: Freefile
Type: function

Returns the next open file slot.

e.g.


f = freefile
open "file.ext" for input as #f

FUNCTION

Syntax: [public | private] function name ([parameter[, parameter...]])
Type: statement

A small block of code used to perform a function based on input parameters, giving a return value. This can be used for example to see if the function performed properly or not using the return value. Functions are either public, or private (default is public).

Function is the same as sub except it allows a return value.

Example of functions:


function twice (x)
twice = x * 2
end function

print twice (10) 'will print 20, as it is twice of 10.



See also sub, exit, public, private.

GET (File I/O)

Syntax: Get #handle, [position], buffer
Type: statement

Reads data from a file in binary mode. Get will fill the variable you use as the buffer with data. If you use an integer as the buffer it will read 4 bytes (integer on 32-bit processor). Get will read any data type to the file in pure binary mode, making it a very versatile data reading command.

e.g.


dim buffer as byte
f = freefile
open "file.ext" for binary as #f
get #f, , buffer
close #f



See also put (file i/o), open.

GET (Graphics)

Syntax: GET [STEP] (x1, y1)-[STEP](x2, y2), arrayname[(idx)]
Type: statement
Category: Gfx

Statement to save a block of pixels data into an array for later use.

'(x1, y1)' and '(x2, y2)' are coordinates of the opposite corners of the graphics blocks to retrieve. The first is the upper-left corner, and the second is the lower-right corner.

'STEP' specifies a pair of coordinates is relative to the last graphics cursor position. STEP before the second pair of coordinates specifies those are relative to the first pair.

'arrayname' is the array where to save the graphical block.

'idx' is the index into 'arrayname' where to begin storing data. If idx is omitted, it is assumed to be 0.

Use this function to save blocks of graphics so you can later use [urlPUT (graphics)[/url] to draw them. The coordinates of the block are affected by the most recent WINDOW and VIEW (graphics) statements, and must be both inside the current clipping region set by VIEW (graphics). The supplied array must be large enough to hold the block you're going to save; the required array size depends on both the block size in pixels and the current color depth. Use the following formulas to compute the right size in bytes:

For color depths 1, 2, 4 and 8:

size = 4 + (w * h)


For color depths 15 and 16:

size = 4 + (w * h * 2)


For color depths 24 and 32:

size = 4 + (w * h * 4)



Where 'w' and 'h' are the width and height of the graphics block you want to save. Assuming you're working with INTEGER arrays, and as an INTEGER in FB is 4 bytes long, to save an 8bpp 32x32 block for example, you'll need an array of (((4 + (w * h)) + 3) / 4) elements.

For an example see put (graphics).

See also PUT (graphics), GET (File I/O), SCREEN (graphics), WINDOW, VIEW (graphics).

Differences:
Between QB:
Contrary to the QB version, this requested array size for an image does not reduce if you are using a mode with color depth less than 8bpp; so your arrays will need to be sized using the formula for 8bpp modes even if you're is 1, 2 or 4bpp modes. Also pay attention when storing pixel data blocks in multidimensional arrays, as QB stored arrays in column-order, whereas FB stores arrays in row-order, so what in QB was achieved with PUT (100, 100), sprites(0, 7), in FB is achieved with PUT (100, 100), sprites(7, 0).

getkey

Type: function

Differences:
New to FreeBasic.

getmouse

Syntax: GETMOUSE x, y[, [wheel][, [buttons]]]
Type: statement
Category: gfx

Statement to retrieve mouse position and buttons status.

Mouse position in screen coordinates is stored in 'x' and 'y' on function termination. If mouse is not present or out of the program window, 'x' and 'y' will hold -1.

'wheel' is the mouse wheel counter. Rotating the wheel away from you makes the count to increase, rotating towards you makes it to decrease. If mouse is not present or out of the program window, wheel will hold -1.

'buttons' stores the button status. On function termination, this will return a bitmask holding buttons status. Bit 0 is set if left mouse button is down; bit 1 is set if right mouse button is down; bit 2 is set if middle mouse button is down.

Use this function to get mouse info while in gfx mode. Pay attention: GETMOUSE does NOT work if a gfx mode is not set. Pass x, y, wheel and buttons variables by reference, so this function will store result values in them. If mouse is not present or out of the program window, all returned values will be -1.

e.g.


' Set video mode and enter loop
DIM x AS INTEGER, y AS INTEGER, buttons AS INTEGER
SCREEN 13
DO
' Get mouse x, y and buttons. Discard wheel position.
GETMOUSE x, y,, buttons
'buttons
LOCATE 1, 1
IF x < 0 THEN
PRINT "Mouse not available or not on window"
ELSE
PRINT USING "Mouse position: ###:### Buttons: "; x; y;
IF buttons AND 1 THEN PRINT "L";
IF buttons AND 2 THEN PRINT "R";
IF buttons AND 4 THEN PRINT "M";
PRINT " "
END IF
LOOP WHILE INKEY$ = ""
END



See also SCREEN (graphics), MULTIKEY, getkey.

Differences:
New to FreeBasic.

GOSUB

Syntax: gosub label
Type: statement

Jumps to a line label and remembers where it came from. Similar to using a sub except it is how it was done with the early basic interpreters.

Gosub is thought as bad programming practice as it can generate unreadable and untracable code. It is better to use sub or function instead.

e.g.


gosub message
end

message:
print "Welcome!
return



See also goto, sub, function.

GOTO

Syntax: goto label
Type: statement

Jumps code execution to a line label.

e.g.


1 goto 3
2 end
3 print "Welcome!
4 goto 2



You may be thinking that code is ugly and unreadable. In all truth it is, and goto's should be avoided for more modern structures such as do...loop, for...next, sub, and function.

See also gosub, sub, function.

HEX$

Syntax: hex$(decimal)
Type: function

returns the hexidecimal value of a decimal number from integer form to a string. Hexidecimal values contain 0-9, and A-F.

e.g.


print hex$(54321)



will return "D431".

See also bin$, oct$.

IF...THEN

Type: statement

IF...THEN is a mechanism to only execute code if a condition is true, and can provide alternative code to execute based on more conditions. Basicly it is a way to make decisions.

the structure is like so:


if condition then
...
[elseif condition then
...]
[else
...]
end if



e.g. here is a simple "guess the number" game using if...then for a decision.


randomize timer
x = rnd * 10

print "guess the number between 0 and 10"

do
input "guess? "; y
if x = y then
print "right!"
exit do
elseif x > y then
print "too low"
elseif x < y then
print "too high"
end if
loop



See also #if, select case.

IMP

Syntax: a imp b
Type: operator
Category: logic

A bitwise operator which is the same as (not a) or b.

See also Logical operators.

INKEY$

Syntax: inkey$
Type: function
Category: Input

Returns the last key pushed on the keyboard.

e.g.


print "press q to quit"
do
loop until inkey$ = "q"



See also input, input$, line input.

Differences:
Between QB:
with extended codes, first char will be 255, not 0.

INP

Syntax: inp &h3c9
Type: function
Category: Gfx

Function for VGA port input emulation.

This function emulates the QB INP function for VGA port access; the only port value this function accepts is &h3C9. You do not normally need this function; use 8bit or higher color depth modes and PALETTE instead.

See also PALETTE, OUT, WAIT, screen (graphics).

Differences:
Between QB:
This command is only supported to emulate palette reading using the gfxlib library. The only port that can be used is &h3c9 (palette port). This is only included to support qb45 programs that use inp for palette manipulation.

Because of this, any other port will return 0.

Reason: User mode apps can't access IO ports directly.

INPUT

Type: statement
Category: Input

INPUT #

Type: statement
Category: File

input (file mode)

Type: keyword
Category: file mode

A file mode used with open to read lines of text from the file.

See also output.

INPUT$

Type: function
Category: Input

INSTR

Syntax: instr ([start,] subject, search)
Type: function

Returns the position in the string 'subject' for the first occurence of the string 'search'. Instr optionally only starts searching past the position 'start'.

If nothing is found it returns 0.

e.g.


print instr("abcdefg", "def")


Will return "4".

See also mid$ (function).

INT

Syntax: int(decimal number)
Type: function

If the input is an integer it returns the integer, otherwise returns the next integer less than the input. e.g. int(4.9) will return 4, and int(-1.3) will return -2.

integer

Type: data type

32-bit signed whole-number data type.

See also uinteger, data types.

Differences:
Between QB:
Now is 32-bit rather than 16-bit due to the 32-bit processors of today.

IS

Type: keyword
Category: control flow

See select case.

KILL

Syntax: kill file$
Type: statement

deletes a file from disk.

e.g.


kill "file.ext"



See also shell.

LBOUND

Syntax: lbound(array[, dimension])
Type: function

Lbound returns the lowest index that can be used in the array 'array'.

Optionally 'dimension' says what dimension to check the lowest bound. 1 for first dimension, and 2 for second dimension etc.

e.g.


dim array(-10 to 10, 5 to 15, 1 to 2) as integer
print lbound(array, 1) 'returns -10
print lbound(array, 2) 'returns 5
print lbound(array, 3) 'returns 1



See also ubound, dim.

LCASE$

Syntax: lcase$ (text$)
Type: function

returns the input string making all letters in lower case.

e.g.

print lcase$("Hello World abCDefGH")



See also ucase$.

LEFT$

Syntax: left$(text$, n)
Type: function

returns 'n' amount of characters starting from the left of 'text$'.

e.g.


text$ = "hello world"
print left$(text$, 5) 'returns "hello"



See also right$, mid$ (function).

LEN

Syntax: len(variable)
Type: function

Returns the size of a variable in bytes. This can be used with strings (returns the length in characters), integers, custom types, etc.

e.g.

print len("hello world") 'returns "11"



This is similar to the cc++ command 'sizeof()'.

Differences:
Between QB:
Works with UDT's and types too.

e.g.


a = a + len( integer )

LET

Syntax: [let ]variable = value
Type: statement

Useless command that does nothing, simply compadible with old basic dialects.

e.g. these two lines have the same effect:


let x = 100
x = 100



As you can see the let statement is not needed.

lib

Differences:
New to FreeBasic.

LINE (Graphics)

Syntax: line [[step] (x1, y1)]-[step] (x2, y2)[, [color][, [b|bf][, style]]]
Type: statement
Category: Gfx

Graphics statement that draws a straight line or a box between two points.

LINE coordinates are affected by last WINDOW and VIEW (graphics) statements, and respect clipping rect set by VIEW (graphics).

e.g. draws a diagonal red line with a white box, and waits for 3 seconds


dim t as single
screen 13
line (20, 20)-(300, 180), 4 'diagonal red line
line (140, 80)-(180, 120), 15, b
t = timer
do
loop until timer > t + 3



See also circle, window, view (graphics).

LINE INPUT

Syntax: LINE INPUT[;] ["promptstring";] stringvariable
Type: statement
Category: Input

To read an entire line of text from the keyboard input and store in a variable.

v1c, unfinished.

LINE INPUT #

Type: statement
Category: File

loc

Syntax: loc (file slot)
Type: function
Category: File

Returns the position with an open file (in binary mode).

See also lof, open.

Differences:
Between QB:
No support to file modes other than the binary file mode.

LOCAL

Type: keyword
Category: Error

LOCATE

Syntax: locate [row][, column]
Type: statement
Category: Console

Sets the console cursor to the row and column given.

Row is the up-down position in the console.
Column is the left-right position in the console.

Differences:
Between QB:
there are no cursor, start and stop optional arguments.

LOCK

Syntax: LOCK fileslot [, {record | [start] TO end}]
Type: statement
Category: File

Lock will restrict access to a file or part of a file if given the record number or the start and end positions.

Lock is useful when multiple programs, people, or threads are trying to access the same file.

See unlock for the opposite command. Unlock uses the same syntax, so to properly lock and unlock a file you will give the same paramaters to unlock that you did to lock.

e.g. locking a file, reading 100 bytes, and unlocking it. To run, make sure there exists a file called 'file.ext' in the current directory that is at least 100 bytes.


dim array(1 to 100)
f = freefile
open "file.ext" for binary as #f
lock #f, 1 to 100
for i = 1 to 100
get #f, i, array(i)
next
unlock #f, 1 to 100
close #f



See also unlock, open.

LOF

Syntax: lof (file slot)
Type: function
Category: File

Returns the length of file of an open file given the file slot.

e.g.


f = freefile
open "file.ext" for binary as #f
print lof(f)
close #f



See also loc, open.

LOG

Syntax: log (number)
Type: function
Category: math

Returns the logarithm of the input 'number' with log base e (natural log). e is approximately 2.718.

To calculate the log base x of a number one would do this:


function LogX! (number!, x!)
LogX! = log(number!) / log(x!)
end function

print LogX!(100, 10) 'returns 2

LONG

Type: data type

See integer, since so far, integers and longs are the same.

See also data types.

LOOP

Type: keyword
Category: control flow

See do...loop.

LSET

Syntax: lset string_var, string_expression
Type: statement
Category: File

LSET left justifies text into the string buffer 'string_var', filling the left part of the string with 'string_expression' and the right part with spaces.

e.g.


buffer$ = space$(10)
lset buffer$, "91.5"
print "-["; buffer$; "]-"



See also rset, space$, put (file i/o), mkd$, mki$, mkl$, mks$.

Differences:
Between QB:
syntax is "LSET dst, src" not "LSET dst = src"

LTRIM$

Type: function

Ltrim (left trim) trims the leading white space.

e.g.


print ltrim$(" hello") 'returns "hello"



See also rtrim$.

MID$ (function)

Syntax: mid$(text$, start[, length])
Type: function

returns a section of a string starting from 'start' for 'length' characters. If 'length' is not used then all of the characters until the end of the string are used.

e.g.


print mid$("abcdefg", 3, 2) 'returns "cd"
print mid$("abcdefg", 3) 'returns "cdefg"
print mid$("abcdefg", 2, 1) 'returns "b"



See also instr, mid$ (statement).

MID$ (statement)

Syntax: mid$(text$, start[, length]) = value$
Type: statement

Allows part of a string to be replaced.

e.g.


text$ = "abc 123"
print text$ 'returns "abc 123"
mid$(text$, 5, 3) = "456"
print text$ 'returns "abc 456"



See also mid$ (function).

MKD$

Syntax: mkd$(number as double)
Type: function

Encodes a double-precision floating point number to a string. Useful with field.

small example on syntax:


dim n as double
n = 1.2345
e$ = mkd$(n)



See also mki$, mkl$, mks$, CVD, CVI, CVL, CVS.

MKDIR

Syntax: mkdir folder$
Type: statement
Category: File

Makes a folder on the local file system.

e.g.

mkdir "data"


makes a folder called 'data' in the current folder.

See also shell, rmdir.

MKI$

Type: function

Encodes a 32bit integer number to a string. Useful with field.

small example on syntax:


dim n as integer
n = 43
e$ = mki$(n)



See also mkd$, mkl$, mks$, CVD, CVI, CVL, CVS.

MKL$

Type: function

Encodes a long number to a string. Useful with field. Since long's in FB are the same as Integers, this is the same as MKI$.

small example on syntax:


dim n as long
n = 31
e$ = mkl$(n)



See also mkd$, mki$, mks$, CVD, CVI, CVL, CVS.

MKS$

Type: function

Encodes a single-precision floating point number to a string. Useful with field.

small example on syntax:


dim n as single
n = 1.2345
e$ = mks$(n)



See also mkd$, mki$, mkl$, CVD, CVI, CVL, CVS.

MOD

Syntax: a mod b
Category: math

Returns the remainder of a divided by b (modulus).

e.g.

print 10 mod 4 'returns "2"

multikey

Syntax: multikey(scancode)
Type: function
Category: Gfx

Function to detect multiple keypresses.

'scancode' is the DOS hardware scancode of the key you want to query for.

This function lets you detect the immediate status of any key at any time; the returned value is -1 if key is pressed, 0 otherwise. The keyboard input buffer is not disabled while you use MULTIKEY; that is, pressed keys will be stored and subsequently returned by your next call to INKEY$. This means you have to empty INKEY$ when you finish using MULTIKEY:

WHILE INKEY$ <> "": WEND



Keeping INKEY$ to work while you use MULTIKEY allows more flexibility and can be useful to detect CHR$(255)+"X" combo returned on window close button click. Pay attention: this function does only work if you are in gfx mode; it does NOT work in console mode. For a list of accepted scancodes, see DOS keyboard scancodes.


Example:


DIM work_page AS INTEGER, x AS INTEGER, y AS INTEGER
' Request 640x480 with 2 pages
SCREEN 18, ,2
COLOR 2, 15
work_page = 0
x = 320
y = 240
DO
' Let's work on a page while we display the other one
SCREENSET work_page, work_page XOR 1
' Check arrow keys and update position accordingly
IF MULTIKEY(&h4B) AND x > 0 THEN x = x - 1
IF MULTIKEY(&h4D) AND x < 639 THEN x = x + 1
IF MULTIKEY(&h48) AND y > 0 THEN y = y - 1
IF MULTIKEY(&h50) AND y < 479 THEN y = y + 1
CLS
CIRCLE(x, y), 30, , , , ,F
' Page flip
work_page = work_page XOR 1
LOOP WHILE NOT MULTIKEY(&h1)
' Clear input buffer
WHILE INKEY$ <> "": WEND
' Restore both work and visible pages to page 0
SCREENSET
PRINT "Press any key to exit..."
SLEEP



See also screen (graphics), INKEY$.

Differences:
New to FreeBasic

NAME

Syntax: NAME oldname as string, newname as string
Type: statement
Category: File

Renames a file originally called oldname to newname.

e.g.

name "dsc001.jpg", "landscape.jpg"


will rename the file "dsc001.jpg" to "landscape.jpg".

Differences:
Between QB:
Name no longer uses the syntax "name oldname as newname" as that syntax is obscure only to this command. Now uses a more structured syntax "name oldname, newname".

NEXT

Type: keyword
Category: control flow

See also for...next.

Differences:
Between QB:
Multiple counters are not supported.

e.g.


NEXT a, b, c

NOT

Syntax: not a
Type: operator
Category: logic

returns true if the condition is false. This swaps the condition from true to false ahd false to true.

i.e.

not &b01010101


will return &b10101010.

See also Logical operators.

OCT$

Syntax: oct$ (n as integer)
Type: function

Returns a number in octal format (base 8) in a string. Octal digits range from 0 to 7, so 8 in decimal is 10 in octal (oct$(8) = "10").

See also bin$, hex$.

ON ERROR

Syntax: on error goto label
Type: statement
Category: Error

ON ERROR triggers a jump to an error handler when an error occurs.

e.g.


on error goto errorhandler 'sets the error handler label
error 24 'simulate error 24
print "this message will not be seen"

errorhandler:
print "Error #"; err; "!" 'show the error number
end 'end the program execution



See also error, err.

ON...GOSUB

Syntax: on expression gosub label1[, label2...]
Type: statement
Category: Keywords

Branches out to different labels depending on the value of an expression. 1 will branch to the first label, 2 to the second, etc. It will also remember where it branched from, and when 'return' is called it will return to where it was branched from.

However this command should be replaced with select case.

Anyway, here is a simple example:


choice = 3
on choice gosub labela, labelb, labelc
print "Good bye."
end

labela:
print "choice a"
return

labelb:
print "choice b"
return

labelc:
print "choice c"
return



See also select case, on...goto, gosub, return.

ON...GOTO

Syntax: on expression goto label1[, label2...]
Type: statement
Category: Keywords

Branches out to different labels depending on the value of an expression. 1 will branch to the first label, 2 to the second, etc.

However this command should be replaced with select case.

Anyway, here is a simple example:


choice = 3
on choice gosub labela, labelb, labelc

labela:
print "choice a"
end

labelb:
print "choice b"
end

labelc:
print "choice c"
end



See also select case, on...gosub, goto.

OPEN

Syntax: open file$ for {file mode} as #slot [LEN=record length]
Type: statement

Opens a file on the system for reading/writing in the given file slot, with the given file mode.

more written here later, but the basics. This example will read a line of text from the file "file.ext" in the current folder, and print the text on the screen.


f = freefile
open "file.ext" for input as #f
line input #f, ln$
print ln$
close #f



See also close, input #, get (file i/o), put (file i/o).

OPTION BASE

Syntax: option base {0 | 1}
Type: statement

Sets the default lower bound of an array subscript.
e.g.


option base 1
dim foo(10)


foo is now an array that ranges from foo(1) to foo(10). This is the same as dim foo(1 to 10). If option base 0 is used, foo would range from 0 to 10.

option private

Syntax: option private
Type: statement

Sets subs/functions to be private by default (instead of public by default). This means subs/functions are only accessible within the module and is hidden to other modules, unless they have 'public' before them. This means two subs/functions can have the same name, as long as they are private and are in seperate modules.

e.g.


option private

sub I_am_private()
end sub

public sub I_am_public()
end sub



See also private, public, sub, function, option base.

Differences:
New to FreeBasic.

OR

Syntax: a or b
Type: operator
Category: logic

A bitwise operator which compares each bit in the two numbers and returns true if either coresponding bits are true. Useful to return true if either conditions are true.

i.e.

&b00110011 or &b01010101


will return &b01110111.

See also Logical operators.

OUT

Syntax: out port, value as byte
Type: statement
Category: Gfx

Statement for VGA port output emulation.

Used for lowlevel VGA palette management emulation, this function only accepts port numbers &h3C7, &h3C8 and &h3C9. You do not normally need this function; use 8bit or higher color depth modes and PALETTE instead.

See also PALETTE, INP, WAIT.

Differences:
Between QB:
This is just a limited emulation, and only ports &h3C7, &h3C8 and &h3C9 are supported for DOS VGA palette DAC registers writing operations. A write to any other port will have no effect.

Reason: user mode apps can't access IO ports directly in windows.

OUTPUT

Type: keyword
Category: file mode

A file mode used with open to allow the file to be written to with lines of text.

See also input (file mode).

PAINT

Syntax: paint [step] (x, y)[, [paint color][, [border color][, background]]]
Type: statement
Category: Gfx

Graphics command to fill an area with a color touching the borders. Also known as 'flood-fill' or 'paint bucket'.

If the 'paint' argument is a number, it is assumed a color in the same format used by the COLOR statement, and the region is flood-filled using that color. If 'paint' is a string, the region will be filled using a pattern; the pattern is always 8x8 pixels, and the passed string must hold pixels data in a format dependent on the current color depth. The string holds pattern pixels row by row, and its size should be as follows:

For color depths 1, 2, 4 and 8:
	size = 8 * 8 = 64
For color depths 15 and 16:
	size = (8 * 8) * 2 = 128
For color depths 24 and 32:
	size = (8 * 8) * 4 = 256



If the passed string is smaller, missing pixels will be 0. Flood-filling continues until pixels of the specified border color are found.

e.g. to draw a white circle painted blue inside, then waits 3 seconds.


dim t as single

screen 13
circle (160, 100), 30, 15
paint (160, 100), 1, 15

t = timer
do
loop until timer > t + 3

Differences:
Between QB:
The QB additional background parameter is not supported.

PALETTE

Type: statement
Category: Gfx

Syntax:

PALETTE [index, color]
PALETTE USING arrayname(idx)



Statement to customize current palette.

'index' is the index of the color to be customized.

'color' is the new color RGB value for specified index.

'arrayname(idx)' is the array of color values to be set.

The PALETTE statement is used to customize the current palette for gfx modes with a color depth of up to 8bpp; using PALETTE while in a mode with a higher color depth will have no effect. Calling PALETTE with no argument restores the default palette for current gfx mode.

If you specify index and color, these are dependent on the current mode:

Screen mode:                       | index range: | color range:
-----------------------------------+--------------+--------------
1                                  |      0-3     |     0-15
2                                  |      0-1     |     0-15
7, 8                               |     0-15     |     0-15
9                                  |     0-15     |     0-63
11                                 |      0-1     |   see below
12                                 |     0-15     |   see below
13, 14, 15, 16, 17, 18, 19, 20, 21 |     0-255    |   see below



In screen modes 1, 2, 7, 8 and 9 you can assign to each color index one of the colors in the available range. In other screen modes, the color must be specified in the form &hBBGGRR, where BB, GG and RR are the blue, green and red components ranging &h0-&h3F in hexadecimal (0-63 in decimal). If you don't like hexadecimal form, you can use the following formula to compute the integer value to pass to this parameter:

color = red or (green shl 8) or (blue shl 16)



Where red, green and blue must range 0-63. The available colors are reset by the SCREEN (graphics) statement to a default palette; see appendix B for details. You can alter the contents of the current palette using the PALETTE statement for modes with a color depth higher or equal to 8, or by using the OUT statement in lower depth modes. Calling PALETTE USING allows to set a list of color values all at once; you should pass an array holding enough elements as the color indices available for your current gfx mode color depth (2 for 1bpp, 4 for 2bpp, 16 for 4bpp or 256 for 8bpp). The array elements must be integer color values in the form described above. The colors stored into arrayname starting with given idx index are then assigned to each palette index, starting with index 0. Any change to the palette is immediately visible on screen.

See also SCREEN (graphics), COLOR, OUT, Default palettes.

pascal

Syntax: declare {function | sub} procName pascal alias
Type: calling convention

Forces the standard pascal calling convention when calling a sub/function.

This exists for compadibility with pascal libraries, so that they can be used with FreeBasic.

See also declare, cdecl, pascal, stdcall.

Differences:
New to FreeBasic.

PCOPY

Syntax: pcopy source, destination
Type: statement
Category: Gfx

Copies one video page to another. Useful for drawing all graphics on one invisible page and copying it to the active visible page - creating smooth graphics and animation. Known as 'double buffering' or 'page flipping'.

'source' and 'destination' refer to page numbers. The 'source' page is copied over the 'destination' page when pcopy is called.

See also FLIP, SCREENCOPY.

PEEK

Type: function

Syntax:
peek(address) as byte (8bit)
peeks(address) as short (16bit)
peeki(address) as integer (32bit)

Peek (in all forms: peek, peeks, and peeki) return the value in memory given by a memory address. This was how pointer features were coded in the old basic dialects.

e.g. of getting the address of a variable and reading its contents by its address:


dim x as byte, addr as integer
addr = varptr(x)
x = 5
print x
print peek(addr)



See also poke.

peeki

Type: function

See peek.

Differences:
New to FreeBasic.

peeks

Type: function

See peek.

Differences:
New to FreeBasic.

PMAP

Syntax: PMAP(coord, func)
Type: function
Category: Gfx

Function to map coordinates between view and physical mapping.

'coord' is an expression indicating the coordinate to be mapped.

'func' is the mapping function number to be applied to given coordinate.

This function allows to convert a coordinate between view (as defined by the WINDOW statement) and physical (as set by the VIEW (graphics) statement) mappings. Depending on the value of func, expr is used to compute a different mapping to be returned by PMAP:

func value:	return value:
0		Treats expr as x view coordinate and returns corresponding
		x physical coordinate.
1		Treats expr as y view coordinate and returns corresponding
		y physical coordinate.
2		Treats expr as x physical coordinate and returns corresponding
		x view coordinate.
3		Treats expr as y physical coordinate and returns corresponding
		y view coordinate.



See also window, view (graphics).

POINT

Type: function
Category: Gfx

Function to read a pixel color or coordinate.

Syntax:
POINT(x, y)
POINT(func)

'(x, y)' are coordinates of the pixel.

Alternatively, 'func' specify which coordinate mapping to return.

When called with two arguments, the specified (x,y) coordinates are affected by the most recent WINDOW and VIEW (graphics) statements; if the pixel lies out of the current clipping region, POINT returns -1, otherwise a color number in the same format as used by the COLOR statement. When called with one argument, this function allows to retrieve the current gfx cursor position; POINT returns a value dependent on the func argument:

func:	return value:
0	Current x physical coordinate.
1	Current y physical coordinate.
2	Current x view coordinate. If the WINDOW statement has not been used,
	this returns the same as POINT(0).
3	Current y view coordinate. If the WINDOW statement has not been used,
	this returns the same as POINT(1).



See also pset, pmap, COLOR, VIEW (graphics), WINDOW.

pointer

Differences:
New to FreeBasic.

POKE

Type: statement

Syntax:
poke address, value as byte '(8bit)
pokes address, value as short '(16bit)
pokei address, value as integer '(32bit)

Poke (in all forms: poke, pokes, and pokei) changes the value in memory given by a memory address. This was how pointer features were coded in the old basic dialects.

e.g. of getting the address of a variable and changing its contents by its address:


dim x as byte, addr as integer
addr = varptr(x)
x = 5
poke addr, 10
print x



See also peek.

pokei

Type: statement

See poke.

Differences:
New to FreeBasic.

pokes

Type: statement

See poke.

POS

Syntax: POS
Type: function
Category: File

Returns the horizontal (left-right) position of the text cursor. 1 means the very left.

e.g.


print "position: "; pos
print "hello world";
print "position: "; pos



See also locate.

Differences:
Between QB:
There's no always-0 argument (it is redundant).

preserve

Syntax: redim preserve array(...) as data type

Used with redim so that when an array is resized, data is not reset but is preserved. This means when the array is enlarged that only new data is reset, while the old data remains the same.

e.g. (v1c, too lazy to see if/how it works :p).


'$dynamic
dim array(1 to 3) as integer
array(1) = 10
array(2) = 5
array(3) = 8
redim preserve array(2 to 10) as integer
for i = 2 to 10
print "array("; i; ") = "; array(i)
next



See also dim, redim.

PRESET

Syntax: PSET [STEP] (x, y)[,color]
Type: statement
Category: Gfx

PRESET works exactly like PSET, except that if the color is not specified,
the background color is selected.

PRINT

Type: statement
Category: Console

Displays text on the screen (or console output).
Print handles complex, specific syntax to handle string constants (like "hello"), number constants (eg 101), string or number variables (eg x or name$), and punctuation symbols like a join (;), or tab space (,).

Using a join allows two items to be printed in one statement like the following:


name$ = "Linus"
print "Name: "; name$



If a print expression ends with a join, the next print statement will be joined beside the last one. for example:


print "Hello ";
print "world";
print "!"



Commas act just like a tab space and a join, for example:


x = 30
print "x is ",
print x
print "hello", "world", "and", "goodbye"



If a print expression doesn't end with a comma or a join then a new line is inserted. If there is no print expression then print simply makes a new line.

e.g.


print "Welcome"
print
print "...and goodbye!"

Simple hello world example:
[code]
PRINT "Hello World!"

PRINT #

Type: statement
Category: File

PRINT USING

Type: statement
Category: Console

private

Type: statement

Explicitly sets an individual sub/function to be private (instead of public by default). This means the sub/function is only accessible within the module and is hidden to other modules. This means two subs/functions can have the same name, as long as they are private and are in seperate modules.

Subs/functions are private by default if the command option private is used, otherwise they are public by default.

e.g.


private sub i_am_private
end sub

sub i_am_public
end sub



See also public, option private, sub, function.

Differences:
New to FreeBasic.

procptr

Type: function

Differences:
New to FreeBasic.

PSET

Syntax: PSET [STEP] (x, y)[,color]
Type: statement
Category: Gfx

Statement to plot a single pixel.

The 'STEP' option specify that 'x' and 'y' are offsets relative to the current graphics cursor position.

'(x, y)' are coordinates of the pixel.

'color' is the color attribute. This is mode specific, see COLOR and SCREEN (graphics) for details.

This function plots a single pixel on the screen. The x and y coordinates are affected by the last call to the VIEW (graphics) and WINDOW statements, and respect the current clipping region as set by the VIEW (graphics) statement. If you do not specify color, current foreground color is used.

See also point, VIEW (graphics), WINDOW.

ptr

Differences:
New to FreeBasic.

public

Type: statement

Explicitly sets an individual sub/function to be public. This means the sub/function is freely accessible between other modules.

The only reason one needs to use the public prefix on subs/functions is if they are private by default (using option private), because subs/functions are public by default normally.

e.g.


option private
sub i_am_private
end sub

public sub i_am_public
end sub



See also private, option private, sub, function.

Differences:
New to FreeBasic.

PUT (File I/O)

Syntax: Put #handle, [position], data
Type: statement

Writes data to a file in binary mode. Put will write any data type to the file in pure binary mode, making it a very versatile data writing command.

e.g.


dim buffer as string
f = freefile
open "file.ext" for binary as #f
buffer = "hello world within a file."
put #f, , buffer
close #f



See also put (file i/o), open.

PUT (Graphics)

Syntax: PUT [STEP] (x, y), arrayname[(idx)][,mode]
Type: statement
Category: Gfx

Statement to draw a block of pixels previously saved by GET.

The 'STEP' option specify that 'x' and 'y' are offsets relative to
the current graphics cursor position.

(x, y) are coordinates where to place the top-left corner of the block to be drawn.

'arrayname' is the array holding saved block pixels data.

'idx' is an Index into arrayname where data is assumed to start. If 'idx' is omitted, it is assumed to be 0.

'mode' is one of PSET, PRESET, AND, OR, XOR or TRANS; see below. If omitted, this defaults to XOR.

PUT can be used to draw images previously saved by the GET (graphics) statement. The 'x' and 'y' coordinates are affected by the last call to the VIEW (graphics) and WINDOW statements, and plotted image respects the current clipping region set by last call to the VIEW (graphics) statement. Pixels stored in given array (source pixels) are drawn on the screen interacting with the pixels onto which they are going to be drawn (destination pixels); the interaction depends on the mode parameter:

mode:		interaction:
PSET		Source pixels overwrite destination pixels.
PRESET		Source pixels are 1-complement negated and written over
		destination pixels.
AND		Destination pixels are bitwise ANDed with source pixels.
OR		Destination pixels are bitwise ORed with source pixels.
XOR		Destination pixels are bitwise XORed with source pixels.
TRANS		Source pixels overwrite destination pixels. If a source pixel
		is the mask color (see below), the pixel is skipped.



The AND, OR and XOR modes produce different results depending on the current color depth, as pixels are stored in different formats; see Internal pixel formats for details. If the TRANS mode is used, pixels using the mask color are not drawn. The mask color depends on the current color depth: in paletted modes (up to 8 bpp) it is equal to color index 0, while on hi/truecolor modes (15, 16, 24 and 32 bpp) it is equal to color &hFF00FF (bright pink). The pixels data stored in given array must be compatible with current gfx mode color depth; that is, if you acquire an image using GET and you later change screen mode via SCREEN (graphics), the image data may not be valid in the new gfx mode, making PUT to behave badly.

Example:


' Set 320x240 mode using 16bpp color depth
SCREEN 14, 16
' Let's allocate space for a 32x32 sprite
DIM sprite((32 * 32 * 2) + 4)
' Let's prepare our sprite
LINE (0,0)-(31,31), &hFF0000, BF
LINE (0,0)-(31,31), &h00FF00, B
LINE (8,8)-(23,23), &hFF00FF, BF
LINE (1,1)-(30,30), &h0000FF
LINE (30,1)-(1,30), &h0000FF
GET (0,0)-(31,31), sprite
' Showtime!
CLS
FOR i = 0 TO 63
LINE (0,i)-(319,i), RGB(i * 4, i * 4, i * 4)
NEXT i
PUT (19, 16), sprite, PSET
PUT (69, 16), sprite, PRESET
PUT (119, 16), sprite, AND
PUT (169, 16), sprite, OR
PUT (219, 16), sprite, XOR
PUT (269, 16), sprite, TRANS
SLEEP



See also get (graphics), PUT (File I/O).

Differences:
Between QB:
FB version supports hi/truecolor sprites, transparency and clipping. For modes with color depth up to 8bpp, it always assumes 1 byte equals 1 pixel into arrayname, whereas QB packs more pixels per byte if color depth is less than 8bpp.

RANDOM

Type: keyword
Category: file mode

The RANDOM keyword is used with the OPEN statement which opens the file with the RANDOM file mode.

The RANDOM file mode allows you to read/write records at any point of the file (unlike sequential access of the append file mode).

See this external resource for examples and more info: http://www.petesqbsite.com/sections/express/issue6/index.html#randomaccessfiles.

get (file i/o), put (file i/o), binary, append, output, input (file mode), field.

RANDOMIZE

Type: statement

Sets the random seed that helps rnd generate random numbers. For good results, using a seed that is not quite predictable provides good results for random numbers.

An example of this is the number of milliseconds past midnight (timer).

e.g.

randomize timer



See also rnd.

READ

Type: statement

Reads data stored in the application with the data command.

See data for an example.

reallocate

Syntax: (function( byval src as any ptr, byval bytes as integer ) as any ptr)
Type: function

Differences:
New to FreeBasic.

REDIM

Type: statement

Changes the size of an array (upper and lower bounds). Using redim to declare an array first forces it to be a dynamic array, where as dim forces an array to be static unless the metacommand $dynamic is used.

e.g. on using dynamic arrays:


'$DYNAMIC
DIM x(10) AS INTEGER
PRINT UBOUND(x)

REDIM x(100) AS INTEGER
PRINT UBOUND(x)



See also dim, ubound, lbound.

REM

Syntax: rem comment
Type: statement

REM is the same as a comment symbol ('). It comments out text. Usually for helpful notes.

e.g.


rem blabla etc etc

RESET

Type: statement
Category: File

Closes all disk files.

See also open, close.

RESTORE

Type: statement

Chooses which embedded data to read from. If your application has a great deal of data embedded within itself, restore allows one to organise the data and select which set of data to start reading from using labels.

Small example:


RESTORE bar
READ x, y
PRINT x, y

foo:
DATA 5, 15
bar:
DATA 8, 13



This example only has a small amount of data, however other applications may have a great deal of data to sort through and restore is useful in this case.

See also data, read.

RESUME

Type: statement
Category: Error

RETURN

Type: statement

Returns from a gosub call.

See gosub.

rgb

Syntax: rgb(red, green, blue)
Type: function
Category: Gfx

Function to compute valid color value for hi/truecolor modes.

'Red', 'green' and 'blue' are components ranging 0-255.

The RGB function can be used to compure a valid color value for use while in hi/truecolor modes. It returns a number in the format &hRRGGBB, where RR, GG and BB equals the values passed to this function, in hexadecimal format.

Example:
See PUT (graphics) example.

See also color.

Differences:
New to FreeBasic.

RIGHT$

Syntax: right$(text$, n)
Type: function

returns 'n' amount of characters starting from the right of 'text$'.

e.g.


text$ = "hello world"
print right$(text$, 5) 'returns "hello"



See also left$, mid$ (function).

RMDIR

Syntax: rmdir folder$
Type: statement
Category: File

Removes a folder from the file system.

e.g. if a folder called "foo" exists and you want it removed:

rmdir "foo"



See also shell, mkdir.

RND

Syntax: rnd
Type: function

Returns a decimal (floating point) number between 0 and 1, based off the random seed (see randomize).

See also randomize.

Differences:
Between QB:
There's no always-0 argument.

RSET

Syntax: rset string_var, string_expression
Type: statement
Category: File

RSET right justifies text into the string buffer 'string_var', filling the right part of the string with 'string_expression' and the left part with spaces.

e.g.


buffer$ = space$(10)
rset buffer$, "91.5"
print "-["; buffer$; "]-"



See also lset, space$, put (file i/o), mkd$, mki$, mkl$, mks$.

Differences:
Between QB:
syntax is "RSET dst, src" not "RSET dst = src"

RTRIM$

Type: function

Rtrim (right trim) trims the trailing white space.

e.g.


print len(rtrim$("hello ")) 'returns "5"



See also ltrim$.

run

Syntax: run file$
Type: statement
Category: Misc

Run will run an executable file (file$) in the file system. After the executable has ended, control will not return to the original caller program, but return to the system.

For example, if the executable "file.exe" exists in the current folder this code will execute it:


run "file.exe"



See also chain.

Differences:
Between QB:
needs the full executable name including extension (.exe).

SADD

Syntax: sadd (stringvar$)
Type: function

Returns the memory offset of the string data in the string variable.

e.g.


print sadd(s$)
s$ = "hello"
print sadd(s$)
s$ = "abcdefg, 1234567, 54321"
print sadd(s$)



See also varptr.

screen (graphics)

Syntax: SCREEN mode[,[ depth][,[ num_pages][, fullscreen]]]
Type: statement
Category: Gfx

Statement to set current gfx mode.

'mode' is the graphics screen mode number, see below.

'depth' is the color depth in bits per pixel. If you omit this argument, the default depth for given mode is set.

'num_pages' is the number of video pages you want, see below. Default if omitted is 1.

'fullscreen' is a flag. Set this argument to 0 to request a windowed mode, 1 to request a fullscreen mode. Default if omitted is 0.

The SCREEN statement sets the current gfx mode. Available modes list follows:

Mode 1: 320x200 in CGA emulation.
	40x25 text format, 8x8 character size.
	16 background colors and one of four sets of foreground colors set by
	the COLOR statement.
Mode 2: 640x200 in CGA emulation.
	80x25 text format, 8x8 character size.
	16 colors assigned to any of 2 attributes.
Mode 7: 320x200 in EGA emulation.
	40x25 text format, 8x8 character size.
	16 colors assigned to any of 16 attributes.
Mode 8: 640x200
	80x25 text format, 8x8 character size.
	16 colors assigned to any of 16 attributes.
Mode 9: 640x350
	80x25 or 80x43 text format, 8x14 or 8x8 character size.
	64 colors assigned to any of 16 attributes.
Mode 11: 640x480
	80x30 or 80x60 text format, 8x16 or 8x8 character size.
	Assignment of up to 256K colors to any of 2 attributes.
Mode 12: 640x480
	80x30 or 80x60 text format, 8x16 or 8x8 character size.
	Assignment of up to 256K colors to any of 16 attributes.
Mode 13: 320x200
	40x25 text format, 8x8 character size.
	Assignment of up to 256K colors to any of 256 attributes.
Mode 14: 320x240
	40x30 text format, 8x8 character size.
	Assignment of up to 256K colors to any of 256 attributes.
Mode 15: 400x300
	50x37 text format, 8x8 character size.
	Assignment of up to 256K colors to any of 256 attributes.
Mode 16: 512x384
	64x24 or 64x48 text format, 8x16 or 8x8 character size.
	Assignment of up to 256K colors to any of 256 attributes.
Mode 17: 640x400
	80x25 or 80x50 text format, 8x16 or 8x8 character size.
	Assignment of up to 256K colors to any of 256 attributes.
Mode 18: 640x480
	80x30 or 80x60 text format, 8x16 or 8x8 character size.
	Assignment of up to 256K colors to any of 256 attributes.
Mode 19: 800x600
	100x37 or 80x75 text format, 8x16 or 8x8 character size.
	Assignment of up to 256K colors to any of 256 attributes.
Mode 20: 1024x768
	128x48 or 128x96 text format, 8x16 or 8x8 character size.
	Assignment of up to 256K colors to any of 256 attributes.
Mode 21: 1280x1024
	160x64 or 160x128 text format, 8x16 or 8x8 character size.
	Assignment of up to 256K colors to any of 256 attributes.



For modes 14 and up, the depth parameter changes the color depth to the specified new one; if depth is not specified, these modes run in 8bpp. For modes 13 and below, depth has no effect. The num_pages parameter specifies the number of "pages" supported by the video mode: a page is either the visible screen or an offscreen buffer the same size of the screen. You can show a page while working on another one; see the SCREENSET statement for details. You can request any number of pages for any video mode; if you omit num_pages, only the visible page (number 0) will be available. Depending on if the fullscreen parameter is 0 or 1, SCREEN will try to set the specified video mode in windowed or fullscreen mode, respectively. If fullscreen is 1 and the system cannot set specified mode in fullscreen, it'll try in windowed mode. If fullscreen is 0 and the system fails to open a window for specified mode, it'll try fullscreen. If everything fails, SCREEN will have no effect and execution will resume from the statement following the SCREEN call. You should take care of checking if a gfx mode has been set or not, and behave accordingly; a way to check if SCREEN is successful is to test the return value of the SCREENPTR function, have a look at it for details. Once a gfx mode has been set, you can toggle fullscreen and windowed mode at any time by pressing ALT-ENTER, providing the system supports it. While in windowed mode, clicking on the window close button will return CHR$(255)+"X" to INKEY$, while clicking on the maximize window button will switch to fullscreen mode if possible. A successful SCREEN call sets currently visible and working pages both to page number 0, resets the palette to the specified mode one (see Default palettes), resets the clipping region to the size of the screen, disables custom coordinates mappings, moves the gfx cursor to the center of the screen, moves the text cursor to the top-left corner of the screen and sets foreground and background colors to bright white and black respectively.

Example:


' Sets fullscreen 640x480 with 32bpp color depth and 4 pages
SCREEN 18, 32, 4, 1
IF NOT SCREENPTR THEN
PRINT "Error setting video mode!"
END
END IF



See also PALETTE, SCREENLOCK, SCREENUNLOCK, SCREENPTR, SCREENSET, SCREENCOPY, SCREENINFO.

Differences:
Between QB:
Parameters differ, FB version allows additional modes and color depths, and
any number of pages in any mode.

screencopy

Syntax: SCREENCOPY [from_page][, to_page]
Type: statement
Category: Gfx

Statement to copy the contents of a graphical page into another graphical page.

'from_page' is the page to copy from. If you omit this argument, the current work page is assumed.

'to_page' is the page to copy to. If you omit this argument, the currently visible page is assumed.

You can use this function to add a double buffer to your graphics. Any SCREEN mode supports this function; you must supply valid page numbers otherwise SCREENCOPY will have no effect. This function has two aliases: FLIP and PCOPY.

Example:
See SCREENSET example.

See also screen (graphics), SCREENSET.

Differences:
Between QB:
Function new in FB: works like the QB PCOPY statement, but works for any gfx mode, providing you requested enough pages.

screeninfo

Syntax: SCREENINFO
Type: function
Category: Gfx

Function to retrieve information about current video mode.

This function can be useful to get current mode informations like gfx driver name, color depth, screen size and more. It returns a pointer to a read-only variable of type SCREENINFOTYPE, defined as follows:


TYPE SCREENINFOTYPE
driver_name AS STRING
w AS INTEGER
h AS INTEGER
depth AS INTEGER
pitch AS INTEGER
bpp AS INTEGER
mask_color AS INTEGER
num_pages AS INTEGER
flags AS INTEGER
END TYPE



Here's a description of available fields:

driver_name	Name of current gfx driver in use, like "DirectX" or "X11".
w		Width of the screen in pixels.
h		Height of the screen in pixels.
depth		Current pixel format bits per pixel: this can be 1, 2, 4, 8,
		16 or 32. See appendix C for details.
pitch		Size of a framebuffer row in bytes.
bpp		Bytes per pixel.
mask_color	Color value for transparent pixels in current mode.
num_pages	Number of available pages.
flags		Mode flags. If bit 0 is set mode is fullscreen, otherwise it's
		windowed.



If no gfx mode is set when you call this function, the returned structure will report "none" as driver_name and 0 to all other fields. If you change video mode via SCREEN (graphics), the informations returned by previous calls to SCREENINFO are invalidated, and you have to recall SCREENINFO to obtain the updated new settings. You never have to deallocate the returned structure.

Example:


TYPE SCREENINFOTYPE
driver_name AS STRING
w AS INTEGER
h AS INTEGER
depth AS INTEGER
pitch AS INTEGER
bpp AS INTEGER
mask_color AS INTEGER
num_pages AS INTEGER
flags AS INTEGER
END TYPE
DIM info AS SCREENINFOTYPE PTR
SCREEN 15, 32
' Obtain info about current mode
info = SCREENINFO
PRINT STR$(info->w) + "x" + STR$(info->h) + "x" + STR$(info->depth);
PRINT " using " + info->driver_name + " driver"
SLEEP



See also screen (graphics), Internal pixel formats.

Differences:
New to FreeBasic.

screenlock

Syntax: screenlock
Type: statement
Category: Gfx

Statement to lock work page framebuffer.

The SCREENLOCK function locks the current work page framebuffer for direct memory access. Once the page is locked, the screen contents stop being updated automatically and you can't call any of the primitive drawing functions until you unlock the page with the SCREENUNLOCK statement. While the work page is locked, you can read/write its memory freely; you must call SCREENUNLOCK when you are done. It is strongly recommended that you hold a page locked for a time as short as possible, and you should also note that you are not supposed to call SCREENLOCK if a lock has not been unlocked first. If the work page is the same as the visible page, any modifications to the page memory while locked will not become visible until SCREENUNLOCK is called.

Example:
See SCREENPTR example.

See also SCREEN (graphics), SCREENUNLOCK, SCREENPTR.

Differences:
New to FreeBasic

screenptr

Syntax: screenptr
Type: function
Category: Gfx

The SCREENPTR function returns a pointer to the current work page framebuffer memory, or NULL (0) if no gfx mode is set. It can be used either to test if a call to SCREEN (graphics) is successful, either to do read/write operations directly to the work page memory, providing the page is first locked and later unlocked via the SCREENLOCK and SCREENUNLOCK statements. The pointer returned by SCREENPTR is only valid after a successful call to SCREEN (graphics), and is invalidated by subsequent calls to SCREEN (graphics).

Example:


' Set good old 320x200 in 8bpp mode
' No pages specified so we have one work page = visible page
SCREEN 13
' We're in an 8bpp mode, so a BYTE PTR is needed for framebuffer access
DIM framebuffer AS BYTE PTR
framebuffer = SCREENPTR
' We need to lock current work page before access is possible
SCREENLOCK
' Plot a white pixel at coordinates 160,100 on the work page
POKE framebuffer + (100 * 320) + 160, 15
' Unlock work page so our change is made visible
SCREENUNLOCK
SLEEP



See also SCREEN (graphics), SCREENLOCK, SCREENUNLOCK, ptr, pointer.

Differences:
New to FreeBasic.

screenset

Syntax: SCREENSET [work_page][, visible_page]
Type: statement
Category: Gfx

Statement to set current work and visible pages.

SCREENSET allows to set the current working page and the current visible page. Page numbers can range 0-(num_pages - 1), where num_pages is the number of pages set by the most recent call to the SCREEN (graphics) statement. You can use this function to achieve page-flipping or double-buffering. If you omit work_page but not visible_page, only visible page is changed. If you omit visible_page but not work_page, only work page is changed. If you omit both arguments, both work page and visible page are reset to page 0.

Example:


' Set good old 320x200 in 8bpp mode, but with 2 pages
SCREEN 13, ,2
COLOR ,15
DIM x AS INTEGER
x = -40
' Let's work on page 1 while we display page 0
SCREENSET 1, 0
DO
CLS
LINE (x, 80)-(x + 39, 119), 4, BF
x = x + 1
IF (x > 319) THEN x = -40
' Wait for vertical sync
WAIT &h3DA, 8
' Copy work page to visible page
SCREENCOPY
LOOP WHILE INKEY$ = ""



See also SCREEN (graphics), SCREENCOPY.

Differences:
New to FreeBasic.

screenunlock

Syntax: SCREENUNLOCK [start_line][, end_line]
Type: statement
Category: Gfx

Statement to unlock work page framebuffer.

'start_line' is an optional argument specifying first screen line to be updated. If you omit this argument, top screen line is assumed.

'end_line' is an optional argument specifying last screen line to be updated. If you omit this argument, bottom screen line is assumed.

SCREENUNLOCK unlocks the current work page assuming it was previously locked by calling SCREENLOCK; do not call SCREENUNLOCK if no page has been locked yet. This function lets the system restart updating the screen regularly, and when called produces the immediate update of the screen region marked by the given start and end lines. When no lock is held, you can again safely call the gfx primitive statements, but you cannot access the work page framebuffer directly via SCREENPTR.

Example:
See SCREENPTR example.

See also SCREEN (graphics), SCREENLOCK, SCREENPTR.

Differences:
New to FreeBasic.

SEEK (return)

Syntax: seek (file slot) as integer
Type: function

Returns the position (in bytes) within a file given the file slot.

e.g.


f = freefile
open "file.ext" for binary as #f
...
position = seek(f)
...
close #f



See also seek (set), open.

SEEK (set)

Syntax: seek (file slot, position)
Type: statement

Sets the position (in bytes) within a file for the next read/write to occur at (given the file slot).

e.g. if you want to skip to the 100th byte in the file for reading/writing:


f = freefile
open "file.ext" for binary as #f
...
seek f, 100
...
close #f



See also seek (return), open.

SELECT CASE

Type: statement

Syntax:

Select case (expression)
case (expression list)
...
[case (expression list 2)
...]
[case else
...]
end select



Select case executes specific code depending on the value of an expression. If the expression matches the first case then it's code is executed otherwise the next cases are compaired and if one case matches then its code is executed. If no cases are matched and there is a 'case else' on the end then it wll be executed, otherwise the whole select case block will be skipped.

Syntax of an expression list:

value [{to value | IS (conditional operator) value}][, ...]



example of expression lists:


...
case 5
case 5 to 10 'make sure the smaller number is to the left of the larger number
case is > 5
case 1, 3 to 10
case 1, 3, 5, 7, 9
...



Example of select case in use:


input "Choose a number between 1 and 10: "; choice
select case choice
case 1
print "number is 1"
case 2
print "number is 2"
case 3, 4
print "number is 3 or 4"
case 5 to 10
print "number is in the range of 5 to 10"
case is > 10
print "number is greater than 10
case else
print "number is less than 1"
end select



See also if...then.

setdate

Syntax: setdate newdate$
Type: statement

To set the date you just format the date and send to SetDate in a valid format following one of the following: "mm-dd-yy", "mm-dd-yyyy", "mm/dd/yy", or "mm/dd/yyyy" (mm is the month, dd is the day, yy and yyyy is the year.

e.g. to set the current date:


month$ = "03" 'march
day$ = "13" 'the 13th
year$ = "1994" 'good ol' days
Setdate month$ + "/" + day$ + "/" + year$



See also date$, timer.

SETENVIRON

Syntax: setenviron "var=value
Type: statement
Category: misc

Modifies system environment variables.

E.g. to set the system variable "path" to "c:":


shell "set path" 'shows the value of path
setenviron "path=c:"
shell "set path" 'shows the new value of path



See also environ$, shell.

Differences:
Between QB:
This is the same as the command ENVIRON command.

SGN

Syntax: sgn (number)
Type: function
Category: math

Returns -1 if the arguement is negative, returns 0 if the arguement is 0, and returns 1 if the arguement is positive.

e.g.


input "Type a number: ", x
print sgn(x)

shared

Type: statement

Shared makes variables to be used in the main code and inside subs/functions.

e.g.


dim shared x as integer
dim y as integer

x = 10
y = 5

MySub

sub mysub
print "x is "; x 'this will report 10 as it is shared
print "y is "; y 'this will not report 5 because it is not shared
end sub



See also dim, common.

Differences:
Between QB:
Only supported when used with DIM, REDIM or COMMON.

shell

Type: statement
Category: Misc

Shell sends commands to the system command prompt.

e.g. for windows:

shell "dir c:\*.*"



e.g. for linux:

shell "ls"

Differences:
Between QB:
Argument is not optional, pass at least "".

shl

Syntax: integer shl integer
Type: operator
Category: math

shifts all bits in the integer (to the left of shl) to the left by the integer given (to the right of shl).

i.e.
&b0110 shl 1 will become &b1100.

This is the opposite of shr.
See also Arithmetic operators.

short

Type: data type

16-bit signed whole-number data type.

See also ushort, data types.

Differences:
The name "short" is new to FreeBasic, however they are the same as integers in QB.

shr

Syntax: integer shr integer
Type: operator
Category: math

shifts all bits in the integer (to the left of shr) to the right by the integer given (to the right of shr).

i.e.
&b0110 shr 1 will become &b0011.

This is the opposite of shl.
See also Arithmetic operators.

SIN

Syntax: SIN (angle as single)
Type: function
Category: math

Returns the sine of the angle (given in radians).

SINGLE

Type: data type

32-bit floating point (decimal) number.

See also data types.

sleep

Syntax: sleep [time]
Type: statement
Category: Misc

If a time is given, sleep will wait 'time' milliseconds.

If no time is given, sleep will wait until the user presses a key.

e.g.


print "press a key"
sleep
print "wait 5 seconds"
sleep 5000



See also timer, inkey$.

Differences:
Between QB:
Has millisecond accuracy, 1 is equal to 1ms, not 1 sec. Also pressing a key does not interrupt the sleep process unless the time limit was omited.

SPACE$

Syntax: space$(n)
Type: function

Returns a string full of spaces, with the length of 'n'.

e.g.


s$ = space$(4)
print "non indented text"
print s$ + "Indented text"
print s$ + "blabla"



See also string$.

SPC

Syntax: spc(n)
Type: function
Category: Console

Redundant although still supported. Use space$ instead.

This was probably a command in old basic dialects. Originally it was only used with print and lprint. Now you can use space$.

SQR

Syntax: sqr (number)
Type: function
Category: math

Returns the square root of the number given.
This is the same as number ^ (1/2).

e.g.


print sqr(9) 'returns 3
print 9 ^ (1/2) 'returns 3
print sqr(20^2) 'returns 20



See also arithmetic operators.

static

Type: statement

Declares variables and arrays which become local to a procedure and preserves values between procedure calls (the values are not destroyed when the procedure is ended).

See also $static.

Differences:
Between QB:
Can be used with arrays too, same way as DIM or REDIM.

stdcall

Syntax: declare {function | sub} procName stdcall alias "procAliasName" (parameterlist...) [as type]
Type: calling convention

See also declare, cdecl, pascal.

v1c, havnt finished example..

Differences:
New to FreeBasic.

STEP

Type: keyword
Category: control flow

See for...next.

stop

Type: statement
Category: Misc

Ends the execution of the program and returns to the system. It is recommended to use end, as this command is provided only to be compadibile with older basic dialects.

See also end.

Differences:
Between QB:
works the same way as END or SYSTEM.

STR$

Syntax: str$( number )
Type: function

Converts a number into a string. This is the opposite function of val.

So str$(3) will become "3",
and str$(-3.1415) will become "-3.1415".

e.g.


dim a as integer
dim b as string
a = 8421
b = str$(a)
print a, b



See also val.

STRING

Type: data type

String is a data type which stores text, words, letters, or characters. An example of "hello" is a string. All strings in FreeBasic are text or letters surrounded in double quotes ("...").

e.g. using strings:


dim message as string
message = "hello world"
print message



see also data types.

STRING$

Type: function

Syntax:
string$(n, code)
string$(n, character$)

String repeats a character (given by the character code number, or a string) 'n' times.

e.g. using string$ to make text underlined:


msg$ = "FreeBasic is a basic compiler"
l = len(msg$)
print string$(l, "-")

SUB

Syntax: [public | private] sub name ([parameter[, parameter...]])
Type: statement

A small block of code used to perform a a sub-program based on input parameters. This is used to code a common bit of code once, and simply called to execute the code. Asin if you have common code that must be executed which is only different by a few values, placing the main bit of code in a sub will save you writing the similar code many times over. Subs are either public, or private (default is public).

Sub is the same as function except it doesnt allows a return value.

Example of writing colored text using a sub:


sub colortext (txt as string, clr as integer)
color clr
print txt
end sub

colortext "blue", 1
colortext "green", 2
colortext "red", 4
print

for i = 1 to 15
colortext "color " + str$(i), i
next



See also function, exit, public, private.

SWAP

Syntax: swap a, b
Type: statement

Swaps the value of two variables.

e.g. using swap to order 2 numbers:


input "input a number: "; a
input "input another number: "; b
if a > b then swap a, b
print "the numbers, in ascending order are:"
print a, b

SYSTEM

Syntax: system
Type: statement
Category: Misc

Closes all open files and returns to the system. This is the same as end and is here for compadibility between older basic dialects. It is recommended to use end instead.

e.g.


print "this text is shown"
system
print "this text will never be shown"



See also end.

TAB

Syntax: tab (column)
Type: function
Category: Console

Special function used with the print statement to set the column in a print expression.


print "foo"; tab(20); "bar"
print "hello"; tab(20); "world"



See also space$, spc, print.

TAN

Syntax: tan (number)
Type: function
Category: math

Returns the tangent of the input number (the number is in radians).

See also sin, cos, atn.

THEN

Type: keyword
Category: control flow

See if...then.

TIME$

Type: function

Returns the current time in the format hh:mm:ss.

e.g.


t$ = time$
print "the current time is: "; time$



See also timer.

Differences:
Betweeb QB:
The time cannot be changed by doing this:

time$ = "12:00:00"

TIME$

Type: function

Returns the current time in the format hh:mm:ss.

e.g.


t$ = time$
print "the current time is: "; time$



See also timer.

Differences:
Betweeb QB:
The time cannot be changed by doing this:

time$ = "12:00:00"

TIMER

Syntax: timer
Type: function

Returns the number of seconds past midnight.

e.g.


print "current time in seconds past midnight: "; timer
print "wait 3 seconds"
now = timer
do
loop until timer > (now + 3)
print "done."



See also time$, date$, setdate.

TO

Type: keyword
Category: range

TO is a keyword with many uses, basicly to give a range for other commands.

TO is used to:

Set the range of iterations used with for...next.

Set the size of an array with dim.

Give a range of accepted case values with select case.

trim$

Type: function

See also ltrim$, rtrim$.

Differences:
New to FreeBasic.

TYPE

Type: statement

Syntax:

TYPE typename [field=number]
var1 as {data type}
...
END type



Type is used to define custom data types containing one or more variables/arrays.

e.g. using type:


type clr
red as ubyte
green as ubyte
blue as ubyte
end type

dim a as clr
a.red = 255
a.green = 128
a.blue = 64
print a.red, a.green, a.blue



See also dim, len.

Differences:
Between QB:
By default, type's are padded to 4 bytes (32bit processor) for speed, but can be compacted using the "field=1" paramater. This can cause problems if you assume the data type is compacted where it might not be, especially when using sockets and other external library types.

UBOUND

Syntax: ubound(array[, dimension])
Type: function

Ubound returns the highest index that can be used in the array 'array'.

Optionally 'dimension' says what dimension to check the highest bound. 1 for first dimension, and 2 for second dimension etc.

e.g.


dim array(-10 to 10, 5 to 15, 1 to 2) as integer
print ubound(array, 1) 'returns 10
print ubound(array, 2) 'returns 15
print ubound(array, 3) 'returns 2



See also lbound, dim.

ubyte

Type: data type

8-bit unsigned whole-number data type.

See also byte, data types.

Differences:
New to FreeBasic.

UCASE$

Syntax: ucase$ (text$)
Type: function

returns the input string making all letters in upper case.

e.g.

print ucase$("Hello World abCDefGH")



See also lcase$.

uinteger

Type: data type

32-bit unsigned whole-number data type.

See also integer, data types.

Differences:
New to FreeBasic.

union

Type: statement

Differences:
New to FreeBasic.

UNLOCK

Syntax: UNLOCK fileslot [, {record | [start] TO end}]
Type: statement
Category: File

Unlock will unlock access to a previously locked file, or part of a file.

See lock to do the opposite (lock access to a file), and for sample code.

unsigned

Syntax: as unsigned {integer-based data type}

Forces an integer-based data type to be unsigned (cannot contain negative numbers, but has it's maximum value doubled).

e.g. notice what is displayed:


dim x as unsigned integer
x = -1
print x

Differences:
New to FreeBasic.

UNTIL

Type: keyword
Category: conditional

UNTIL is used with the do...loop structure. See it for more info.

ushort

Type: data type

16-bit unsigned whole-number data type.

See also short, data types.

Differences:
New to FreeBasic.

VAL

Syntax: val( number$ )
Type: function

Converts a string to a number. The number must appear at the beginning of the string. This is the opposite function of str$.

e.g. val("10") will return 10,
and val("-271.3") will return -271.3.
If the string is invalid (asin doesnt contain a number) the result will be 0 (val("abcd") is 0).

e.g.


dim a as string, b as integer
a = "123"
b = val(a)
print a, b



See also str$.

VARPTR

Syntax: varptr(variable)
Type: function

Returns the memory address of a variable. This was used for pointer features in older basic dialects, and is still useful for pointer arithmetic in FreeBasic.

An example of using varptr:


dim a as integer, addr as integer
a = 10
addr = varptr(a)
pokei addr, -1000
print a
poke addr + 1, 128 'change 1/2 of the bits using basic pointer arithmetic
print a



See also poke

VIEW (Graphics)

Syntax: VIEW [[SCREEN] (x1, y1)-(x2, y2)[,[ color][, border]]]
Type: statement
Category: Gfx

Statement to define new physical coordinates mapping and clipping region.

'SCREEN' - When specified, any x,y coordinate will be relative to the top-left corner of the screen, and not to the left-top corner of the viewport.

'x1',y1','x2','y2' - Coordinates of the top-left and bottom-right corners of the new viewport.

'color' - Color with which to clear the new viewport; if you omit this argument, the viewport will not be cleared.

'border' - Color of the border box surrounding the new viewport. If you omit this argument, no border box will be drawn.

Use this statement to set a new clipping region, also known as viewport. The new viewport will override the previous one, if any; if the SCREEN argument is omitted, all future coordinates specifications will be relative to the top-left corner of the new viewport, instead of relative to the top-left corner of the screen. Any graphical primitive will be affected by the new viewport, and drawing outside specified region will produce no effect. If color is specified, in the same format as the one supported by COLOR, the new viewport is cleared with it; if border is specified, also in COLOR format, a box using border as color will be drawn surrounding given region. If all arguments are omitted, the viewport is reset to the screen mode size.

See also SCREEN (graphics), WINDOW, PMAP, VIEW (Text).

VIEW (Text)

Type: statement
Category: Console

Sets the boundaries of the console screen text area.

lillo: is this supported in linux?

Differences:
diff: scrolling quirks may not be exactly the same.

WAIT

Syntax: WAIT port, and_expr[, xor_expr]
Type: statement
Category: Gfx

Statement for DOS port data waiting emulation. This is here for compadibility and is not recommended to be used.

'port' - DOS port number onto wait data for.

'and_expr' - Integer expression to be ANDed with data from the port; if the result of this operation is not 0, the statement returns.

'xor_expr' - Integer expression to be XORed with data from the port, before passing it to and_expr. If you omit this argument, 0 is assumed.

The only port number WAIT supports is &h3DA, for vertical blank syncing. You should only call WAIT this way:

WAIT &h3DA, 8



Any other combination of port, and_expr and xor_expr will have no effect.

Example:
See the SCREENSET example.

See also INP, OUT.

Differences:
Between QB:
This is just an emulation of the QB WAIT statement, and only supports port number &h3DA. This is because it is specific to DOS, many other platforms cannot access ports directly.

WEND

Type: keyword
Category: control flow

See while...wend.

WHILE...WEND

Type: statement
Category: control flow

Syntax:
While condition
...
Wend

While...wend repeats the statements between while and wend, while the condition is true.

e.g.


x = 10
while x > 5
print "x is :"; x
x = x - 1
wend



See also do...loop.

width

Syntax: width columns, rows
Type: statement
Category: Console

Sets the console screen size in windows. This command doesnt work in linux.

e.g.


width 40, 25
print "hello"

Differences:
Between QB:
Only works for console, no file or printer.

WINDOW

Syntax: WINDOW [[SCREEN] (x1, y1)-(x2, y2)]
Type: statement
Category: Console

Statement to define new view coordinates mapping for current viewport.

'SCREEN' - Optional argument specifying y coordinates increase from top to bottom.

'x1','y1','x2','y2' - New floating point values corresponding to the opposite corners of the current viewport.

WINDOW is used to define a new coordinates system. '(x1,y1)' and '(x2,y2)' are the new coordinates to be mapped to the opposite corners of the current viewport; all future coordinates passed to gfx primitive statements will be affected by this new mapping. If SCREEN is omitted, the new coordinates system will be cartesian, that is, with y coordinates increasing from bottom to top. Call WINDOW with no argument to disable the coordinates transformation.

See also SCREEN (graphics), VIEW (graphics), pmap.

Windowtitle

Syntax: WINDOWTITLE title$
Type: statement
Category: Gfx

Statement to set the program window title.

'title$' - String to be assigned as new window title.

This statement is useful to change the program window title. The new title set will become active immediately if the program already runs in windowed mode, otherwise will become the new title for any window produced by subsequent calls to the SCREEN (graphics) statement. If you never call this function before setting a new windowed mode via SCREEN (graphics), the program window will have your executable file name without extension as title by default.

Example:


WINDOWTITLE "FreeBASIC example program"
SCREEN 15
SLEEP



See also screen (graphics).

Differences:
New to FreeBasic.

WRITE (File I/O)

Type: statement
Category: File

WRITE (Screen I/O)

Type: statement
Category: Console

XOR

Syntax: a xor b
Type: operator
Category: logic

XOR is "either one or the other" logic. This is the same as or but it will not be true if both bits are true.

A bitwise operator which compares each bit in the two numbers and returns true if either bit is true, but not if both are true. Useful to return true if either conditions are true.

i.e.

&b00110011 or &b01010101


will return &b01100110.

See also Logical operators.


Unsupported commands

These commands are not supported because they are specific to quickbasic using dos, they are rendered useless due to more efficient ways of code, or they are not worth coding. Some commands have specific reasons next to them why they are not supported.

command line options

Listing of FBC command line help.

 

Usage: fbc [options] inputlist

inputlist:    xxx.a = library, xxx.o = object, xxx.bas = source

options:
-a      add an object file to linker's list
-b      add a source file to compilation
-c            compile only, do not assemble or link
-d  define a preprocessor's constant
-e            add error checking
-g            add debug info (testing)
-l      add a library file to linker's list
-m      main file w/o .ext (entry point)
-o      output name (in the same number as source files)
-s      subsystem (gui, console)
-v            verbose
-x      executable name