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.
Type: metacommand
Differences:
New to Freebasic.
Type: metacommand
Differences:
New to Freebasic.
Type: metacommand
Differences:
New to Freebasic.
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
Differences:
New to FreeBasic.
Syntax: #ifdef symbol
Type: metacommand
This is a shortcut to:
#if defined(symbol)
#ifdef symbol
Differences:
New to Freebasic.
Syntax: #ifndef symbol
Type: metacommand
This is a shortcut to:
#if not defined(symbol)
#ifndef symbol
Differences:
New to Freebasic.
Syntax: #undef identifier
Type: metacommand
Undefines a symbol previously defined with #define.
Differences:
New to Freebasic.
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.
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)
Differences:
New to FreeBasic.
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.
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.
Syntax: ABS (number)
Type: function
Category: math
ABS returns the positive number of the number given.
e.g:
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.
Type: function
Category: math
See also atn.
Differences:
New to FreeBasic.
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:
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:
Differences:
New to FreeBasic.
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
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)
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.
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.
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.
Type: function
Category: math
Allows the use of inline assembly (machine code) used.
Syntax:
asm ... 'asm code end asm
Differences:
New to FreeBasic
Type: function
Category: math
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).
Syntax: BEEP
Type: statement
Category: Misc
BEEP tells the system to sound a beep noise.
Example:
Differences:
Between QB: In Qb this was a single tone noise generated through the pc speaker. Now this may not be the case.
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.
Differences:
New to FreeBasic.
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).
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.
Differences:
Between QB:
Supports blocks of data with sizes bigger than 64K.
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:
Differences:
Between QB:
Files saved using the FB version of BSAVE are incompatible with files saved using the QB BSAVE.
See also byval.
Differences:
New to FreeBasic.
Type: data type
8-bit signed whole-number data type.
See also ubyte, data types.
Differences:
New to FreeBasic.
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.
Syntax: CALL subname ([parameter list])
Type: statement
Calls a sub like in this code snipet:
Differences:
Between QB:
Function must have been declared already.
same as ALLOCATE, but clears the contents.
Differences:
New to FreeBasic.
Type: statement
Redundant, and the same as call. Kept for compadibility reasons.
Differences:
Between QB:
Function must have be declared already.
Type: keyword
Category: control flow
See select case.
Type: function
Converts any numeric expression to a byte.
e.g. this will try convert 260 into 8-bits.
Differences:
New to FreeBasic.
Type: function
Converts any numeric expression to a double-precision number.
cDbl can be explained like so: C-DBL, C (convert) Dbl (double).
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.
Differences:
New to FreeBasic.
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).
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)
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.
Type: function
Converts any number to an integer by removing the fractional part.
See also int.
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:
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.
Syntax: clear pointer, value, bytecount
Type: statement
Resets all values in an array to what you want (usually 0 is useful).
e.g.
Type: function
Converts any number to a long number. The name can be explained by c-lng (c for convert, lng for long).
Type: statement
Closes one file (in a given file slot #) or closes all files (with no parameter given).
Syntax: CLS
Type: statement
Category: Console
Clears the console screen.
Differences:
Between QB:
There's no optional argument, the whole screen is cleared.
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).
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.
Type: function
Returns command line parameters used to call the program.
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.
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:
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!)
Differences:
New to FreeBasic.
Syntax: COS (angle as single)
Type: function
Category: math
Returns the cosine of the angle (given in radians).
Converts any numeric expression to a short integer (16-bit).
No example.
Differences:
New to FreeBasic.
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).
Differences:
New to FreeBasic.
Type: function
Converts any number to a single-precision number.
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).
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.
Differences:
New to FreeBasic.
Syntax: curdir$
Type: function
Category: file
Returns the current directory/folder.
e.g.
Differences:
New to FreeBasic.
Syntax: CVD(8-byte-string)
Type: function
Converts an 8-byte-string created with MKD$ back to a double-precision number.
Syntax: CVI(2-byte-string)
Type: function
Converts a 2-byte-string created with MKI$ back to an integer.
Syntax: CVL(4-byte-string)
Type: function
Converts a 4-byte-string created with MKL$ back to a
long integer.
Syntax: CVS(4-byte-string)
Type: function
Converts a 4-byte-string created with MKS$ back to a single-precision number.
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:
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).
Type: keyword
Used to return the current date, or set a new date for the system.
e.g. to get the current date:
Differences:
Between QB:
To set the date, you must use SETDATE now.
Syntax: (sub( byval src as any ptr ))
Type: statement
Deallocates memory allocated with allocate. See allocate for more details.
Differences:
New to FreeBasic.
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:
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:
Differences:
New to FreeBasic.
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:
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 ?
Differences:
New to FreeBasic.
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:
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:
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:
Differences:
New to FreeBasic.
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:
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:
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:
Differences:
New to FreeBasic.
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:
Differences:
New to FreeBasic.
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:
Differences:
New to FreeBasic.
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:
Differences:
Between QB:
if using non-constants as indexes, use REDIM or $DYNAMIC first. (This may change in the future).
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:
Differences:
Between QB:
New addition to FreeBasic.
Type: statement
Category: control flow
Repeats a block of statements until/while a contition is met.
Syntax 1:
do [{until | while} condition] loop
do loop [{until | while} condition]
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.
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"
Type: conditional
see if...then.
Type: keyword
Category: conditional
see if...then.
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
Type: keyword
Category: conditional
See also if...then.
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.
Type: statement
Category: Misc
See setenviron.
Differences:
Between QB:
called setenviron now.
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":
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.
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
Syntax: Erase array [, array...]
Type: statement
Erases dynamic arrays from memory, or clears all elements in a static array.
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.
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:
Differences:
Between QB:
error numbers are not the same as in QB.
Syntax: (function( program as string, arguments as string ) as integer)
Type: function
Differences:
New to FreeBasic.
Syntax: exepath as string
Type: function
Returns the path of the progam itself. Usually the same as curdir$.
e.g.
Differences:
New to FreeBasic.
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
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.
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.
Category: gfx
Alias for PCOPY and SCREENCOPY. See SCREENCOPY for details.
Differences:
New to QB.
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:
* ** *** **** ***** ****** ******* ******** ********* **********
Differences:
Between QB:
doesn't support implicit pointers (ie: byref vars) as counters.
e.g.
Syntax: fre
Type: function
Category: Misc
Returns the free memory (ram) avaliable in bytes.
Differences:
Between QB:
value doesn't matter, always returns the free physical mem available.
Syntax: Freefile
Type: function
Returns the next open file slot.
e.g.
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:
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.
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:
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).
Type: function
Differences:
New to FreeBasic.
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.
Differences:
New to FreeBasic.
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.
Syntax: goto label
Type: statement
Jumps code execution to a line label.
e.g.
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.
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:
Syntax: a imp b
Type: operator
Category: logic
A bitwise operator which is the same as (not a) or b.
See also Logical operators.
Syntax: inkey$
Type: function
Category: Input
Returns the last key pushed on the keyboard.
e.g.
Differences:
Between QB:
with extended codes, first char will be 255, not 0.
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.
Type: statement
Category: Input
Type: statement
Category: File
Type: keyword
Category: file mode
A file mode used with open to read lines of text from the file.
See also output.
Type: function
Category: Input
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.
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.
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.
Type: keyword
Category: control flow
See select case.
Syntax: kill file$
Type: statement
deletes a file from disk.
e.g.
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.
Syntax: lcase$ (text$)
Type: function
returns the input string making all letters in lower case.
e.g.
Syntax: left$(text$, n)
Type: function
returns 'n' amount of characters starting from the left of 'text$'.
e.g.
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.
Differences:
Between QB:
Works with UDT's and types too.
e.g.
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:
Differences:
New to FreeBasic.
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
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.
Type: statement
Category: File
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.
Type: keyword
Category: Error
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.
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.
Syntax: lof (file slot)
Type: function
Category: File
Returns the length of file of an open file given the file slot.
e.g.
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:
Type: data type
See integer, since so far, integers and longs are the same.
See also data types.
Type: keyword
Category: control flow
See do...loop.
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.
Differences:
Between QB:
syntax is "LSET dst, src" not "LSET dst = src"
Type: function
Ltrim (left trim) trims the leading white space.
e.g.
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.
Syntax: mid$(text$, start[, length]) = value$
Type: statement
Allows part of a string to be replaced.
e.g.
Syntax: mkd$(number as double)
Type: function
Encodes a double-precision floating point number to a string. Useful with field.
small example on syntax:
Syntax: mkdir folder$
Type: statement
Category: File
Makes a folder on the local file system.
e.g.
Type: function
Encodes a 32bit integer number to a string. Useful with field.
small example on syntax:
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:
Type: function
Encodes a single-precision floating point number to a string. Useful with field.
small example on syntax:
Syntax: a mod b
Category: math
Returns the remainder of a divided by b (modulus).
e.g.
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:
Differences:
New to FreeBasic
Syntax: NAME oldname as string, newname as string
Type: statement
Category: File
Renames a file originally called oldname to newname.
e.g.
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".
Type: keyword
Category: control flow
See also for...next.
Differences:
Between QB:
Multiple counters are not supported.
e.g.
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
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$.
Syntax: on error goto label
Type: statement
Category: Error
ON ERROR triggers a jump to an error handler when an error occurs.
e.g.
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:
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:
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.
Syntax: option base {0 | 1}
Type: statement
Sets the default lower bound of an array subscript.
e.g.
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.
Differences:
New to FreeBasic.
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
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.
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).
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
Differences:
Between QB:
The QB additional background parameter is not supported.
Type: statement
Category: Gfx
Syntax:
PALETTE [index, color] PALETTE USING arrayname(idx)
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
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.
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.
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:
Type: function
See peek.
Differences:
New to FreeBasic.
Type: function
See peek.
Differences:
New to FreeBasic.
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.
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).
Differences:
New to FreeBasic.
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:
Type: statement
See poke.
Differences:
New to FreeBasic.
Type: statement
See poke.
Syntax: POS
Type: function
Category: File
Returns the horizontal (left-right) position of the text cursor. 1 means the very left.
e.g.
Differences:
Between QB:
There's no always-0 argument (it is redundant).
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).
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.
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:
Type: statement
Category: File
Type: statement
Category: Console
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.
Differences:
New to FreeBasic.
Type: function
Differences:
New to FreeBasic.
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.
Differences:
New to FreeBasic.
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.
Differences:
New to FreeBasic.
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.
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.
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.
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.
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.
Type: statement
Reads data stored in the application with the data command.
See data for an example.
Syntax: (function( byval src as any ptr, byval bytes as integer ) as any ptr)
Type: function
Differences:
New to FreeBasic.
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:
Syntax: rem comment
Type: statement
REM is the same as a comment symbol ('). It comments out text. Usually for helpful notes.
e.g.
Type: statement
Category: File
Closes all disk files.
See also open, close.
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:
Type: statement
Category: Error
Type: statement
Returns from a gosub call.
See gosub.
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.
Syntax: right$(text$, n)
Type: function
returns 'n' amount of characters starting from the right of 'text$'.
e.g.
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:
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.
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.
Differences:
Between QB:
syntax is "RSET dst, src" not "RSET dst = src"
Type: function
Rtrim (right trim) trims the trailing white space.
e.g.
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:
Differences:
Between QB:
needs the full executable name including extension (.exe).
Syntax: sadd (stringvar$)
Type: function
Returns the memory offset of the string data in the string variable.
e.g.
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.
Differences:
Between QB:
Parameters differ, FB version allows additional modes and color depths, and
any number of pages in any mode.
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.
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:
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.
Differences:
New to FreeBasic.
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
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:
Differences:
New to FreeBasic.
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:
Differences:
New to FreeBasic.
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.
Syntax: seek (file slot) as integer
Type: function
Returns the position (in bytes) within a file given the file slot.
e.g.
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:
Type: statement
Syntax:
Select case (expression) case (expression list) ... [case (expression list 2) ...] [case else ...] end select
value [{to value | IS (conditional operator) value}][, ...]
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:
Syntax: setenviron "var=value
Type: statement
Category: misc
Modifies system environment variables.
E.g. to set the system variable "path" to "c:":
Differences:
Between QB:
This is the same as the command ENVIRON command.
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.
Type: statement
Shared makes variables to be used in the main code and inside subs/functions.
e.g.
Differences:
Between QB:
Only supported when used with DIM, REDIM or COMMON.
Type: statement
Category: Misc
Shell sends commands to the system command prompt.
e.g. for windows:
Differences:
Between QB:
Argument is not optional, pass at least "".
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.
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.
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.
Syntax: SIN (angle as single)
Type: function
Category: math
Returns the sine of the angle (given in radians).
Type: data type
32-bit floating point (decimal) number.
See also data types.
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.
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.
Syntax: space$(n)
Type: function
Returns a string full of spaces, with the length of 'n'.
e.g.
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$.
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.
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.
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.
Type: keyword
Category: control flow
See for...next.
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.
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.
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:
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:
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:
Syntax: swap a, b
Type: statement
Swaps the value of two variables.
e.g. using swap to order 2 numbers:
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.
Syntax: tab (column)
Type: function
Category: Console
Special function used with the print statement to set the column in a print expression.
Syntax: tan (number)
Type: function
Category: math
Returns the tangent of the input number (the number is in radians).
See also sin, cos, atn.
Type: keyword
Category: control flow
See if...then.
Type: function
Returns the current time in the format hh:mm:ss.
e.g.
Differences:
Betweeb QB:
The time cannot be changed by doing this:
Type: function
Returns the current time in the format hh:mm:ss.
e.g.
Differences:
Betweeb QB:
The time cannot be changed by doing this:
Syntax: timer
Type: function
Returns the number of seconds past midnight.
e.g.
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.
Type: function
Differences:
New to FreeBasic.
Type: statement
Syntax:
TYPE typename [field=number] var1 as {data type} ... END type
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.
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.
Type: data type
8-bit unsigned whole-number data type.
See also byte, data types.
Differences:
New to FreeBasic.
Syntax: ucase$ (text$)
Type: function
returns the input string making all letters in upper case.
e.g.
Type: data type
32-bit unsigned whole-number data type.
See also integer, data types.
Differences:
New to FreeBasic.
Type: statement
Differences:
New to FreeBasic.
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.
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:
Differences:
New to FreeBasic.
Type: keyword
Category: conditional
UNTIL is used with the do...loop structure. See it for more info.
Type: data type
16-bit unsigned whole-number data type.
See also short, data types.
Differences:
New to FreeBasic.
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.
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:
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).
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.
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:
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.
Type: keyword
Category: control flow
See 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.
Syntax: width columns, rows
Type: statement
Category: Console
Sets the console screen size in windows. This command doesnt work in linux.
e.g.
Differences:
Between QB:
Only works for console, no file or printer.
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.
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:
Differences:
New to FreeBasic.
Type: statement
Category: File
Type: statement
Category: Console
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
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.
Unsupported.
Type: statement
Reason: This functions is redundant due to inline assembly.
Unsupported.
Type: statement
Reason: This functions is platform dependant on DOS and intel x86 platforms giving no reason for it to be supported on other platforms.
Unsupported.
Type: statement
Reason: user mode apps can't access IO ports directly.
Unsupported.
Type: function
Unsupported.
Type: function
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: function
Unsupported.
Type: function
Unsupported.
Type: function
Reason:
Probably because this returns the line number after an error where this is more of an interprer feature and FreeBasic is a compiler only. This would need more debugging symbols to be inserted mostly causing bloat for little gain.
Unsupported.
Type: statement
Category: File
reason: most hacked statement ever, use records instead.
See get (file i/o), put (file i/o).
Unsupported.
Type: function
Category: File
reason: depends on internal tables
Unsupported.
Type: statement
Category: File
reason: use dir$ instead.
Unsupported.
Type: statement
Unsupported.
Type: function
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Unsupported.
Type: function
Unsupported.
Type: statement
Category: Misc
reason: no direct printing, use proper API's instead.
Unsupported.
Type: function
Unsupported.
Type: function
Unsupported.
Type: keyword
Unsupported.
Type: keyword
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: function
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: statement
Too specific and not needed by most. If anybody wants this functionality a music library would be more practical.
This was barely practical in the 80's with the pc speaker. Anyone who wants this feature should rethink motives, or be shot.
Unsupported.
Type: function
Unsupported.
Type: function
Unsupported.
Type: keyword
Reason: This functions is platform dependant on DOS
and intel x86 platforms, and redundant due to more efficient network models.
Unsupported.
Type: statement
Category: Misc
Reason: Uses the pc speaker, not very useful.
Unsupported.
Type: function
Unsupported.
Type: function
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: statement
Unsupported.
Type: function
Unsupported.
Type: function