Visual Basic


Types

String

String

"This is a string!"

Integer

Integer

64

Boolean

Boolean value (either True or False)

True

Long

Double

Char

Byte

Double

Arithmetic operators

+

Addition

1 + 2

Unary positive, makes number positive

+2

-

Subtraction

2 - 1

Unary negative, makes number negative

-2

*

Multiplication

2 * 3

/

Division

4 / 2

//

Floor division (rounds division down)

4 // 2

Mod

Modulo (remainder of division)

4 % 2

^

Indice

4 ^ 2

Assignment operators

=

Equals

x = 2

+=

a+=b is a=a+b

x += 2

-=

a-=b is a=a-b

x -= 2

*=

a*=b is a=a*b

x *= 2

/=

a/=b is a=a/b

x /= 2

//=

a/=b is a=a//b

x //= 2

%=

a%=b is a=a%b

x %= 2

&=

a&=b is a=a&b

x &= 2

|=

a|=b is a=a|b

x |= 2

^=

a^=b is a=a^b

x ^= 2

>>=

a>>>=b is a=a>>>b

x >>= 2

<<=

a><<=b is a=a><<b

x <<= 2

Comparison operators

=

Is equal to

1 = 2

<>

Is not equal to

1 != 2

>

Greater than

1 > 2

<

Less than

1 < 2

>=

Greater than or equal to

1 >= 2

<=

Less than or equal to

1 <= 2

Bitwise operators

&

Bitwise AND

0b11001010&0b00100011

|

Bitwise OR

0b11001010|0b00100011

^

Bitwise XOR

0b11001010^0b00100011

<<

Arithmetic shift left (shifts all the bits one space to the left, essentially multiplying it by 2)

0b11001010<<2

>>

Logical shift right (shifts all the bits one space to the right, essentially dividing it by 2)

0b11001010>>2

~

Bitwise NOT

~0b11001010

Boolean operators

And

AND operator

True and False

Or

OR operator

True or False

Not

NOT operator

not True

Identity operators

Is

Checks if two objects are the exact same object, not just the same value

IsNot

Checks if two objects aren't the exact same object, even if they have the same value

Identity operators

is in

Checks if an object is an element of another

is not in

Checks if an object isn't an element of another

Miscellaneous operators

.

Applies method to object

list.sort()

Denotes class of an object

math.sqrt(2)

Denotes instance of an object

,

Used to separate parameters

[]

Instantiates data values of a list

list = ["A", 2]

Reference operator for a sequence container

thirdElement = list[2]

Denotes generics of a function

()

Defines a tuple

tuple = ("A", 2)

Denotes parameters of a function

print("Hello world!")

Denotes a class' superclass

class Foo(Parent):

Declares a function

{}

Instantiates a dictionary

dict = {
1 : "A",
2 : "B",
}

Instantiates a class object

->

Return annotation for functions, although doesn't force that return type

def foo(args) -> int:

:

Defines a block

if x == 1:

Defines a lambda expression

x = lambda a : a+1

""

Declares a string

"This is a string!"

''

Declares a string

'This is a string!'

*

The splat; indicates unknown amount of arguments for a parameter and treats them as one tuple

def foo(*args):

&

Concatenates strings

'These are '&'two strings!'

@

Decorator operator; denotes a method decorator (a function wrapped around another function)

Key word

Set

Used for declaring or initializing variables

Sub

Used for declaring subroutines (functions)

If

Executes code if condition is true

Then

Used for declating code to execute when if statement is true

Else

End

Ends a statement

For

Each

In

Try

Catch

Finally

Throw

With

Dim

Used for importing objects

As

Used for denoting alias of an object imported with Dim

Msg Box

Displays a window with text

Await

Await

True

Represents a true boolean value

True

False

Represents a false boolean value

False

Statements

If statement

For statement

While statement

Sub statement

Object

Objects in VBA

Application

Worksheet

Workbook

Range

Rows

Columns

Range

Sheets

Collection of Chart and Worksheet objects

Range

Methods

FileSystemObject

Methods

Folder

Methods

File

LINQ

Database query language integrated in VB, potential tool for employer

Enumerations

Methods

Copy

set.add(object)

Paste

set.add(object)

Select

Selects a

set.add(object)

Delete

Move

GetOpenFilename

CreateObject

Creates a specified object

CreateTextFile

Creates a text file

Object.CreateTextFile(path[String], overwrite[Boolean], unicode[Boolean])

WriteLine

Writes a line to a text file

Close

Closes a text file

InStr

Dir

FileDateTime

CreateObject

Commenting

'

Used to tell compiler the rest of this line is not to be compiled

' This isn't executed