Boolean type

Available from version 5.4.7.

In AskiaScript, a boolean variable contains a boolean value (true or false).

The boolean value is internally stored as a number where zero means false and all other values are interpreted as true. It is therefore possible to use all properties, methods and operators available for numbers with boolean variables.

In this topic:

Creating a boolean type variable

To create a boolean type variable, simply assign a boolean value to a variable.

Examples
Dim valueA As Boolean = True

Dim valueB As Boolean = 1

Dim valueC As Boolean = False

Dim valueD As Boolean = 0

Dim valueE As Boolean = 126  ' => valueE = True
valueE.ToInt() ' => 1

↑ Top of page ↑

Methods

ToNumber()

Converts a boolean value to a number:

Returns a Number.

Examples
dim ok As Boolean = true
ok.ToNumber() ' => 1
dim ok As Boolean = 12456
ok.ToNumber() ' => 1
dim not_ok As Boolean = false
not_ok.ToNumber() ' => 0

↑ Top of page ↑

ToString()

Converts a boolean to string.

Returns a String.

dim ok As Boolean = true
ok.ToString() ' => "true"
dim not_ok As Boolean = false
not_ok.ToString() ' => "false"

↑ Top of page ↑

TypeOf()

Always returns "boolean".

Returns a String.

dim my_boolean As Boolean = true 
my_boolean.TypeOf() ' => "boolean"

' Without the AS Boolean, the type of the variable is a number
dim my_variable = true 
my_variable.TypeOf() ' => "number"

↑ Top of page ↑

Operators

Note: All mathematical operators are available with boolean variables. There is an implicit conversion to an integer, so 0 is used for False and 1 for True.
Warning: All comparison ( =, <>, Has, etc.) with boolean return a Number

 

Name

Symbol / Expression Description Example
Equal = Test the equality
Returns a number
To use it for comparison, the condition should be between brackets else it will be consider as an assignment operator
dim i As Boolean = false
(i = true) ' => False
(i = false) ' => True
Different <> Test the inequality
Returns a number
dim i As Boolean = false
i <> true ' => True
i <> false ' => False
Negate Not() Negate a statement
Returns a number or boolean
dim i As Boolean = true
dim j As Boolean = false
Not(i) ' => False ' => Boolean
Not(j) ' => True ' => Boolean
Not((i = j)) ' => True ' => Number
Not((i <> j)) ' => False ' => Number
And And Use this operator to define statements which are based on a specific combination of two or more variables
Returns a boolean
dim i As Boolean = true
dim j As Boolean = false
dim c As Boolean = true
dim d As Boolean = false
i And j ' => False
j And d ' => False
i And c ' => True
Or Or Use this operator to define statements which are based on a two or more interchangeable/equivalent statements
Returns a boolean
dim i As Boolean = true
dim j As Boolean = false
dim c As Boolean = true
dim d As Boolean = false
i Or j ' => True
j Or d ' => False
i Or c ' => True

 

↑ Top of page ↑

Create your own Knowledge Base