User Tools

Site Tools


k8:k8.6:start

8.6 Special operators

8.6.1 Part 1

The selection of the special operators in this chapter was made according to purely subjective criteria. This is because, for example, the operations increment and decrement in gambas are counted as arithmetic functions that change the value of a variable to the nearest one. You already got to know this view in chapter 8.2 of the arithmetic operators MOD and DIV. So you could consider the functions INC and DEC as unary operators:

OperatorDescription
INC numVariableThe value of the numeric variable is increased by 1. Analogous would be the calculation numVariable = numVariable +1 or numVariable += 1
DEC numVariableThe value of the numeric variable is decreased by 1. Analogous would be the calculation numVariable = numVariable -1 or numVariable -= 1
Expression IS ClassReturns TRUE if an object is an instance of a class or its descendants. Expression is any expression that returns an object reference and Class is a class name.
Expression NOT IS ClassReturns TRUE if an object is not an instance of a class or its descendants.

Table 8.6.1: Special operators

Examples:

PRINT ["Gambas", "rules!"] IS String[]
True

DIM myTextBox AS NEW TextBox(ME)
PRINT myTextBox IS Control
True

PRINT ["Gambas", "rules!"] IS Collection
False

PRINT ["Gambas", "rules!"] NOT IS Collection
True

8.6.2 Part 2 - !-operator

The !-operator is a special operator for certain container objects that allow access to their elements using a string. Examples of such classes are Collection and Result, but also graphical controls like ListView.

The key string is written after the! operator, so that 'hCollection!FirstName' is equivalent to 'hCollection[“FirstName”]'. The return value is the value of the element with the key “FirstName”.

sCurrent.FirstName = hResult!FirstName
sCurrent.FirstName = hResult["FirstName"] ' Alternative
The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k8/k8.6/start.txt · Last modified: 07.02.2022 (external edit)

Page Tools