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).

DATA should not be allowed inside procs (v1c)

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).
DIM|REDIM array w/o explicit dimensions is not allowed anymore inside procs, as the descriptor size is unknown (v1c)

Single variables are declared simply like so:
New syntax  DIM AS INTEGER Lb, Ub, I, J, M, M1
DIM array(), dynamic arrays with unknown dimensions as in VBDOS/VB (v1c)

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"

DYLIBLOAD

DYLIBLOAD and DYLIBSYMBOL intrinsic functions to manage dynamic libraries at runtime (lillo)

DYLIBSYMBOL

DYLIBLOAD and DYLIBSYMBOL intrinsic functions to manage dynamic libraries at runtime (lillo)