BScript Run-time Functions

There are more than 25 built-in run-time functions available in BScript.

Math

ABS(x)

Description

Returns the absolute value of x.

Example

This will print 2.6

print abs(-2.6)

PI

Description

Returns the value of PI (3.14159265359).

Example

This will print the PI constant.

print "pi is", pi

SIN(x)

Description

Returns the sine of x, where x is given in radians.

Return Value

Returns a number between -1 and 1.

Examples

To be written.

COS(x)

Description

Returns the cosine of x, where x is given in radians.

Return Value

Returns a number between -1 and 1.

Examples

To be written.

TAN(x)

Description

Returns the tangent of x, where x is given in radians.

Examples

To be written.

ASIN(x)

Description

Calculates the arc sine of x; that is the value whose sine is x. If x falls outside the range -1 to 1, this function fails.

Return Value

Returns the arc sine in radians, defined to be between -PI/2 and PI/2.

Examples

To be written.

ACOS(x)

Description

Calculates the arc cosine of x; that is the value whose cosine is x. If x falls outside the range -1 to 1, this function fails.

Return Value

Returns the arc sine in radians, defined to be between -PI/2 and PI/2.

Examples

To be written.

ATN(x)

Description

Calculates the arc tangent of x; that is the value whose tangent is x.

Return Value

Returns the arc tangent in radians, defined to be between -PI/2 and PI/2.

Examples

To be written.

LOG(x)

Description

Returns the base-10 logarithm of x.

EXP(x)

Description

Returns the value of e raised to the power x. e is the base of natural logarithms.

SQR(x)

Description

Returns the non-negative square root of x. If x is negative, this function will fail.

INT(x)

Description

Returns the largest integer less than or equal to x. Note that this is not trucated integer, for which see CINT.

Example

This will print 4

print int(4.77)

CINT(x)

Description

Returns the trucated integer of x. See also function INT.

Example

This will print -2

print cint(-2.3)

String

VAL(string$)

Description

Converts a string to number.

Example

This will print 2.3

print val("2.3")

STR$(number)

Description

Converts a number to string.

Example

This will print 1.23

x=1.23
print str$(x)

CHR$(asc)

Description

Returns a character with ASCII code of asc

Example

This will print A since 65 is ASCII code for character A.

print chr$(65)

ASC(string)

Description

Gets ASCII code of first character in string

Example

This will print 72 since 72 is ASCII code for character H.

print asc("Hello")

LEN(s)

Description

Calculates length of the string s.

Return Value

Returns the number of characters in s.

Example

This will print 14.

name$="Linus Torvalds"
print len(name$)

LEFT$(string,n)

Description

Gets first n characters from string. Returns a new string.

Example

This will print Linus

name$="Linus Torvalds"
print left$(name$,5)

RIGHT$(string,n)

Description

Gets last n characters from string.

Example

This will print Torvalds

name$="Linus Torvalds"
print right$(name$,8)

MID$(string,pos,n)

Description

Gets n characters, starting at pos from string. If n is not specified, that this function will gets all characters starting from pos.

Example

This will print Delano

name$="Franklin Delano Roosevelt"
print right$(name$,10,6)

UPPER$(string)

Converts a string to uppercase. Return a new string with all characters converted to uppercase.

Example

This will print BIG CITY

city$ = "big ciTY"
print upper$(city$)

LOWER$(string)

Converts a string to lowercase. Return a new string with all characters converted to lowercase.

Example

This will print romeo and juliet

title$ = "Romeo and Juliet"
print lower$(title$)

Miscellaneous

DATE$

Description

Returns current date as string with format yyyy-mm-dd

Example

On April 20, 1980, this will print 1980-05-20

print date$

TIME$

Description

Returns current time as string with format hh:mm:ss

Example

On 17:24, this will print 17:24

print time$

RND()

Description

Returns a pseudo-random number between 0 and 1.

RANDOMIZE expression

Description

Initializes the seed for a new sequence of pseudo-random to be returned by function RND. The expression is optional, you might want to use function TIMER for this.

TIMER

Description

Returns number of seconds elapsed since midnight. On most cases, TIMER is used as the argument to RANDOMIZE.

Example

randomize timer

ENVIRON$(name)

Description

Returns the environment variable associated with name.

Example

This will print out your PATH environment variable.

print environ$("PATH")