Jump to content

Programming Gambas from Zip/Operators

From Wikibooks, open books for an open world

Operators

[edit | edit source]

Arithmetic

[edit | edit source]

http://Gambaswiki.org/wiki/lang/arithop by example:

- 6

x = - x

Unary minus

Changes number to a negative

5 / 2 = 2.5 Divide
3 + 2 = 5 Add 3 ^ 2 = 9 Power of
7 – 4 = 3 Subtract 13 \ 2 = 6

13 DIV 2 = 6

Integer division
5 * 2 = 10 Multiply 12 % 7 = 5

12 MOD 7 = 5

Remainder after dividing

Boolean

[edit | edit source]
Two things combined, or one thing operated on Overall Value Examples
SomethingTrue AND SomethingTrue True (1=1) AND (2=2) is TRUE

(1<2) AND (5>4) is TRUE

Both have to be true to make the whole thing true.

SomethingTrue AND SomethingFalse False (1=1) AND (2=3) is FALSE

(6>5) AND (4<3) is FALSE

SomethingFalse AND SomethingTrue False (5=6) AND (4=4) is FALSE
SomethingFalse AND SomethingFalse False (5=6) AND (2=3) is FALSE
NOT SomethingTrue False NOT (8=8) is FALSE

NOT (1 > -1) is FALSE

“Not” means “the opposite of”

NOT SomethingFalse True NOT (1=2) is TRUE

NOT ("apple" > "banana") is TRUE

i.e., the reverse of (a comes after b)

SomethingTrue OR SomethingTrue True (1=1) OR (2=2) is TRUE

Either one being true will make the whole thing true.

SomethingTrue OR SomethingFalse True (1=1) OR (2=3) is TRUE
SomethingFalse OR SomethingTrue True (7=3) OR (3=3) is TRUE
SomethingFalse OR SomethingFalse False (1=1) OR (2=3) is FALSE
SomethingTrue XOR SomethingTrue False (1=1) XOR (4=4) is FALSE
SomethingTrue XOR SomethingFalse True (1=1) XOR (4=5) is TRUE
SomethingFalse XOR SomethingTrue True (1=5) XOR (4=4) is TRUE
SomethingFalse XOR SomethingFalse False (1=2) XOR (4=5) is FALSE

AND = both

OR = either

XOR = either, but not both (“exclusive OR”)

String Operators

[edit | edit source]
Joining (Concatenation)
String & String Concatenates two strings.
String &/ String Concatenate two strings that contain file names. Add a path separator between the two strings if necessary.

An example of a path is

/home/gerard/Documents/Gambas/

How to get it:

User.Home &/ "Documents" &/ "Gambas/"

Comparison
String = String Returns if two strings are equal.
String == String Case-insensitive comparison

Returns if two strings are equal, regardless of upper or lower case

String LIKE String Checks if a string matches a pattern. Is the first string like the second? There are special codes for the pattern string. Refer to the wiki for more codes, http://Gambaswiki.org/wiki/lang/like

* means any character or string of characters

"Gambas" Like "G*" means “Does Gambas begin with a G?”

? means any single character; [ ] means either/or the things in brackets:

"Gambas" Like "?[Aa]*" means “Does Gambas have a capital or small A as its second letter?”

"Gambas" Like "G[^Aa]*" means “Does Gambas not have a capital or small A as its second letter?”

Dim Fruit As String = "pear"

Label1.text = Fruit Like "{apple,pear,lemon}"

shows True, but

Label1.text = Fruit Like "{apple, pear, lemon}"

shows False because spaces matter.

String MATCH String Checks if a string matches a PCRE regular expression. Refer to http://Gambaswiki.org/wiki/doc/pcre

PCRE means Perl Compatible Regular Expressions

Regular expressions are the ultimate in finding things in strings.

String BEGINS String Checks if a string begins a certain way

"Gerard" Begins "G" means “Does Gerard begin with a G?”

String ENDS String Checks if a string ends a certain way

"Benôit" Ends "t" means “Does Benôit end with a t?”

String <> String Does not equal, or “is not the same as”
String1 < String2 Does string1 come alphabetically before string2?
String1 > String2 Does string1 come alphabetically after string2?
String1 <= String2 Does string1 come alphabetically before, or is it the same as, string2?
String1 >= String2 Does string1 come alphabetically after, or is it the same as, string2?
Programming Gambas from Zip
 ← Constants Operators DataTypes →