SADD

Syntax: sadd (stringvar$)
Type: function

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

e.g.


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



See also varptr.

screen (graphics)

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

Statement to set current gfx mode.

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

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

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

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

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

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



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

Example:


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



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

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

screencopy

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

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

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

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

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

Example:
See SCREENSET example.

See also screen (graphics), SCREENSET.

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

screeninfo

Syntax: SCREENINFO
Type: function
Category: Gfx

Function to retrieve information about current video mode.

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


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



Here's a description of available fields:

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



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

Example:


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



See also screen (graphics), Internal pixel formats.

Differences:
New to FreeBasic.

screenlock

Syntax: screenlock
Type: statement
Category: Gfx

Statement to lock work page framebuffer.

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

Example:
See SCREENPTR example.

See also SCREEN (graphics), SCREENUNLOCK, SCREENPTR.

Differences:
New to FreeBasic

screenptr

Syntax: screenptr
Type: function
Category: Gfx

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

Example:


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



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

Differences:
New to FreeBasic.

screenset

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

Statement to set current work and visible pages.

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

Example:


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



See also SCREEN (graphics), SCREENCOPY.

Differences:
New to FreeBasic.

screenunlock

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

Statement to unlock work page framebuffer.

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

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

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

Example:
See SCREENPTR example.

See also SCREEN (graphics), SCREENLOCK, SCREENPTR.

Differences:
New to FreeBasic.

SEEK (return)

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

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

e.g.


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



See also seek (set), open.

SEEK (set)

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

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

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


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



See also seek (return), open.

SELECT CASE

Type: statement
- SELECT CASE AS CONST statement, only integer constants are allowed and a jump table is generated making the it much
faster than an ordinary SELECT when more than 4 CASE's have to be checked (v1c)


Syntax:

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

Select case executes specific code depending on the value of an expression. If the expression matches the first case then it's code is executed otherwise the next cases are compaired and if one case matches then its code is executed. If no cases are matched and there is a 'case else' on the end then it wll be executed, otherwise the whole select case block will be skipped. 
Syntax of an expression list: 
value [{to value | IS (conditional operator) value}][, ...]

example of expression lists:

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

Example of select case in use:

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


See also if...then.

setdate

Syntax: setdate newdate$
Type: statement

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

e.g. to set the current date:


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



See also date$, timer.

SETENVIRON

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

Modifies system environment variables.

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


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



See also environ$, shell.

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

SETMOUSE

SETMOUSE gfx statement to set mouse position and cursor visibility (lillo)

SGN

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

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

e.g.


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

shared

Type: statement

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

e.g.


dim shared x as integer
dim y as integer

x = 10
y = 5

MySub

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



See also dim, common.

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

shell

Type: statement
Category: Misc

Shell sends commands to the system command prompt.

e.g. for windows:

shell "dir c:\*.*"



e.g. for linux:

shell "ls"

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

shl

Syntax: integer shl integer
Type: operator
Category: math

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

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

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

short

Type: data type

16-bit signed whole-number data type.

See also ushort, data types.

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

shr

Syntax: integer shr integer
Type: operator
Category: math

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

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

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

SIN

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

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

SINGLE

Type: data type

32-bit floating point (decimal) number.

See also data types.

sleep

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

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

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

e.g.


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



See also timer, inkey$.

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

SPACE$

Syntax: space$(n)
Type: function

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

e.g.


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



See also string$.

SPC

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

Redundant although still supported. Use space$ instead.

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

SQR

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

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

e.g.


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



See also arithmetic operators.

static

Type: statement

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

See also $static.

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

stdcall

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

See also declare, cdecl, pascal.

v1c, havnt finished example..

Differences:
New to FreeBasic.

STEP

Type: keyword
Category: control flow

See for...next.

stop

Type: statement
Category: Misc

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

See also end.

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

STR$

Syntax: str$( number )
Type: function

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

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

e.g.

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

See also val.

 

strcat

(See http://docs.netive.ru/susv3/idx/is.html )
strcat - concatenate two strings

The strcat() function shall append a copy of the string pointed to by s2 (including the terminating null byte) to the end of the string pointed to by s1. The initial byte of s2 overwrites the null byte at the end of s1. If copying takes place between objects that overlap, the behavior is undefined.

RETURN VALUE

The strcat() function shall return s1; no return value is reserved to indicate an error.


strchr

(See http://docs.netive.ru/susv3/idx/is.html )
strrchr - string scanning operation
 

The strrchr() function shall locate the last occurrence of c (converted to a char) in the string pointed to by s. The terminating null byte is considered to be part of the string.

RETURN VALUE

Upon successful completion, strrchr() shall return a pointer to the byte or a null pointer if c does not occur in the string.

strcmp
(See http://docs.netive.ru/susv3/idx/is.html )
compare two strings

The strcmp() function shall compare the string pointed to by s1 to the string pointed to by s2.

The sign of a non-zero return value shall be determined by the sign of the difference between the values of the first pair of bytes (both interpreted as type unsigned char) that differ in the strings being compared.

RETURN VALUE

Upon completion, strcmp() shall return an integer greater than, equal to, or less than 0, if the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2, respectively.

strcpy

(See http://docs.netive.ru/susv3/idx/is.html )
strcpy - copy a string

The strcpy() function shall copy the string pointed to by s2 (including the terminating null byte) into the array pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined.

RETURN VALUE

The strcpy() function shall return s1; no return value is reserved to indicate an error

strlen

(See http://docs.netive.ru/susv3/idx/is.html )
strlen - get string length

The strlen() function shall compute the number of bytes in the string to which s points, not including the terminating null byte.

RETURN VALUE

The strlen() function shall return the length of s; no return value shall be reserved to indicate an error.

 

strncat

(See http://docs.netive.ru/susv3/idx/is.html )
strncat - concatenate a string with part of another
 

The strncat() function shall append not more than n bytes (a null byte and bytes that follow it are not appended) from the array pointed to by s2 to the end of the string pointed to by s1. The initial byte of s2 overwrites the null byte at the end of s1. A terminating null byte is always appended to the result. If copying takes place between objects that overlap, the behavior is undefined.

RETURN VALUE

The strncat() function shall return s1; no return value shall be reserved to indicate an error.

strncmp
(See http://docs.netive.ru/susv3/idx/is.html )
compare part of two strings
 

The strncmp() function shall compare not more than n bytes (bytes that follow a null byte are not compared) from the array pointed to by s1 to the array pointed to by s2.

The sign of a non-zero return value is determined by the sign of the difference between the values of the first pair of bytes (both interpreted as type unsigned char) that differ in the strings being compared.

RETURN VALUE

Upon successful completion, strncmp() shall return an integer greater than, equal to, or less than 0, if the possibly null-terminated array pointed to by s1 is greater than, equal to, or less than the possibly null-terminated array pointed to by s2 respectively.

ERRORS

strncpy

(See http://docs.netive.ru/susv3/idx/is.html )
strncpy - copy part of a string
 

The strncpy() function shall copy not more than n bytes (bytes that follow a null byte are not copied) from the array pointed to by s2 to the array pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined.

If the array pointed to by s2 is a string that is shorter than n bytes, null bytes shall be appended to the copy in the array pointed to by s1, until n bytes in all are written.

RETURN VALUE

The strncpy() function shall return s1; no return value is reserved to indicate an error.

strrchr

(See http://docs.netive.ru/susv3/idx/is.html )
strrchr - string scanning operation
 

The strrchr() function shall locate the last occurrence of c (converted to a char) in the string pointed to by s. The terminating null byte is considered to be part of the string.

RETURN VALUE

Upon successful completion, strrchr() shall return a pointer to the byte or a null pointer if c does not occur in the string.

strstr

(See http://docs.netive.ru/susv3/idx/is.html )
strstr - find a substring
 

The strstr() function shall locate the first occurrence in the string pointed to by s1 of the sequence of bytes (excluding the terminating null byte) in the string pointed to by s2.

RETURN VALUE

Upon successful completion, strstr() shall return a pointer to the located string or a null pointer if the string is not found.

If s2 points to a string with zero length, the function shall return s1.

STRING

Type: data type

String is a data type which stores text, words, letters, or characters. An example of "hello" is a string. All strings in FreeBasic are text or letters surrounded in double quotes ("...").
inline string indexing as in "char = somestring[idx]" (V1c)

e.g. using strings:


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



see also data types.

STRING$

Type: function

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

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

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


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

SUB

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

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

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

Example of writing colored text using a sub:


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

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

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



See also function, exit, public, private.

SWAP

Syntax: swap a, b
Type: statement

Swaps the value of two variables.

e.g. using swap to order 2 numbers:


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

SYSTEM

Syntax: system
Type: statement
Category: Misc

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

e.g.

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

See also end.