bs Variables

Beas Script  variables are containers for storing data values.

Variables can be defined with setvar or can be declared with int, number,date

 

Variables defined with setvar is always data type String

Many functions support only variables defined with setvar, example userevents.

 

In this example, x, y, and z, are variables:

 

Example

setvar=x=3
setvar=y="6"

 

Operators not working with variables defined with setvar
To read a variable, you must insert the variable in brackets <..>

setvar=x=3
setvar=y=<x>

 

 

Alternative you can work with declared variable

Follow Variable types supported: Decimal, Integer, String, Boolean, Datetime

decimal x=3.5
x=<x>+5
// return 8.5
messagebox=<x> 

 

Much Like Algebra

In this example, price1, price2, and total, are variables:

 

Example

decimal price1=5
decimal price2=3.5
decimal total
total= <price1> + <price2>
messagebox=<total>

 

In programming, just like in algebra, we use variables (like price1) to hold values.

In programming, just like in algebra, we use variables in expressions (total= <price1> + <price2>).

 

From the example above, you can calculate the total to be 8.5.

BeasScript variables are containers for storing data values.

 

 

BeasScript Identifiers

All BeasScript variables must be identified with unique names.

These unique names are called identifiers.

Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).

Write all names in lower case!

 

The general rules for constructing names for variables (unique identifiers) are:

 

Names can contain letters, digits, underscores, and dollar signs.

Names must begin with a letter

Names can also begin with _ (but we will not use it in this tutorial), but not with $

Names are case sensitive (y and Y are different variables, write always all in lower case)

 

The Assignment Operator

In beas Script, the equal sign (=) is an "assignment" operator and  an "equal to" operator.

 

decimal x=3.5
x=<x>+3
messagebox=<x>

 

In JBScript, however, it makes perfect sense: it assigns the value of <x> + 3 to x.

(It calculates the value of x + 3 and puts the result into x. The value of x is incremented by 6.)

 

The "equal to" operator is written like = in BeasScript

 

BeasScript Data Types

BeasScript variables can hold numbers like 100 and text values like "Martin".

In programming, text values are called text strings.

BeasScript can handle many types of data, but for now, just think of numbers and strings.

In BeasScript you can use single or double quote for define Text, but this is not mandatory

You must declare variables with decimal, string or you can define string variables with setvar.

 

Example

 

// save 3.14 in String variable "pi"
setvar=pi=3.14
// Save text "Martin" in variable "person"
setvar=person="Martin" 
// Save text "Yes I am!" in variable "answer". quotes not mandatory
setvar=answer=Yes I am!

 

 

 

Declaring (Creating) BeasScript Variables

 

You can define variables with

setvar=myVariable=<value>

This is always from type String and used in most of places in Beas.

Note: UserEvents support only variables declared with setvar

 

Or you define Variables

Decimal pi=3.14
String person="Martin"

If variable type is defined as string, quotes are mandatory

 

Note: it's not possible to declare more then one variable in one line

WRONG:

Decimal a=3.14,b=2.4

Correct:

Decimal a=3.14
Decimal b=2.4
 

Visibility of variables

Beas Script is always window based. It is possible to declare "global" variables, but it's not good to use it

Declaration

Description

setvar

Variable is visible inside the current window from moment of declaration

decimal, string, datetime, boolean

Variable is visible only inside the current function. Variable is not visible in functions, which called from current function

instance decimal

instance string

Variable is visible inside current window from moment of declaration