ABS

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

ABS returns the positive number of the number given.

e.g:


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

ACCESS

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

ACCESS is used with the open statement.

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


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

acos

Type: function
Category: math

See also atn.

Differences:
New to FreeBasic.

ALIAS

Type: clause

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

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


declare sub xClearScreen alias "ClearVideoScreen" ()

allocate

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

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

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


dim a as integer ptr

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

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

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

'deallocate space
deallocate(a)

print ""
sleep



See also deallocate.

Differences:
New to FreeBasic.

AND

Syntax: number1 AND number2
Type: operator
Category: logic

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

Example with (&b0110 AND &b0101)

0110
0101
----
0100

result: &b0110

ANY

Type: clause

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

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


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

APPEND

Type: keyword
Category: file mode

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

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

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

ARRAY

array fields can now be passed by descriptor, as in "array(idx).arrayfield()" (v1c)

AS

Type: clause

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

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

Specify variable type within a user defined type with type

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

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

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

ASC

Syntax: ASC(string) as integer
Type: function

Returns the ascii code of the first character in the string. This has the opposite effect of chr$.
ASC now has an optional parameter to retrieve a char at a specific position as in "c = asc( "abc", 2 )" (v1c)
e.g.

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

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

asin

Type: function
Category: math

See also atn, acos.

asm

Allows the use of inline assembly (machine code) used.
the ASM statement can be used on a single line as in "ASM mov eax, 1234" (v1c)

Syntax:

asm
 ... 'asm code
end asm

e.g. multiplying two integers with asm.


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

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

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

sleep


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

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

mulintegers = res

end function

Differences:
New to FreeBasic

atan2

Type: function
Category: math

See also atn, acos, asin.

ATN

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

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