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
also - exit for
Repeats execution of a code block a number of times, with a counter
increasing/decreasing signifying which iteration the for loop is at.
FOR was accepting UDT fields as counter (v1c)
e.g. to print a triangle of stars:
Output:
* ** *** Example of a counter:
See also do...loop.
Differences:
Between QB:
doesn't support implicit pointers (ie: byref vars) as counters.
e.g.
'a' is an implicit pointer, and this is not supported.
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
nameless arguments on function prototypes as in "BYVAL AS INTEGER" (v1c)
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.
Variable-arguments, as in C: "sub foo(byval bar as integer, ...)" (v1c)
va_first(), va_arg() and va_next() intrinsic macros, to access
variable-arguments in FB functions (v1c)
Example of functions:
See also sub, exit,
public, private.
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.
See also put (file i/o), open.
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.
Gfx GET and PUT now support both arrays and generic pointers as data holders
(lillo)
'(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:
For color depths 15 and 16:
For color depths 24 and 32:
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).
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.
See also SCREEN (graphics),
MULTIKEY, getkey.
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.
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.