
VB.Net is a simple, modern, object-oriented computer programming language developed by Microsoft to combine the power of .NET Framewor...
Everything is in this blog
VB.Net is a simple, modern, object-oriented computer programming language developed by Microsoft to combine the power of .NET Framewor...
Visual Basic .NET (VB.NET) is an object-oriented computer programming language implemented on the .NET Framework. Although it is an evo...
In this chapter, we will discuss the tools available for creating VB.Net applications. We have already mentioned that VB.Net is part o...
Before we study basic building blocks of the VB.Net programming language, let us look a bare minimum VB.Net program structure so that ...
VB.Net is an object-oriented programming language. In Object-Oriented Programming methodology, a program consists of various objects t...
Data types refer to an extensive system used for declaring variables or functions of different types. The type of a variable determine...
A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in VB.Net has a specific type...
The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals. ...
The modifiers are keywords added with any programming element to give some especial emphasis on how the programming element will behav...
A statement is a complete instruction in Visual Basic programs. It may contain keywords, operators, variables, literal values, const...
The VB.Net compiler directives give instructions to the compiler to preprocess the information before actual compilation starts. All t...
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. VB.Net is rich in built-in ...
Replace these every slider sentences with your featured post descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions.
Replace these every slider sentences with your featured post descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions.
Replace these every slider sentences with your featured post descriptions.Go to Blogger edit html and find these sentences.Now replace these with your own descriptions.
Imports System Module Module1 'This program will display Hello World Sub Main() Console.WriteLine("Hello World") Console.ReadKey() End Sub End ModuleWhen the above code is compiled and executed, it produces the following result:
Hello, World!Let us look various parts of the above program:
Imports System Public Class Rectangle Private length As Double Private width As Double 'Public methods Public Sub AcceptDetails() length = 4.5 width = 3.5 End Sub Public Function GetArea() As Double GetArea = length * width End Function Public Sub Display() Console.WriteLine("Length: {0}", length) Console.WriteLine("Width: {0}", width) Console.WriteLine("Area: {0}", GetArea()) End Sub Shared Sub Main() Dim r As New Rectangle() r.Acceptdetails() r.Display() Console.ReadLine() End Sub End ClassWhen the above code is compiled and executed, it produces the following result:
Length: 4.5 Width: 3.5 Area: 15.75In previous chapter, we created a Visual Basic module that held the code. Sub Main indicates the entry point of VB.Net program. Here, we are using Class that contains both code and data. You use classes to create objects. For example, in the code, r is a Rectangle object.
Dim r As New Rectangle()A class may have members that can be accessible from outside class, if so specified. Data members are called fields and procedure members are called methods.
Shared Sub Main() Dim r As New Rectangle() r.Acceptdetails() r.Display() Console.ReadLine() End Sub
AddHandler | AddressOf | Alias | And | AndAlso | As | Boolean |
ByRef | Byte | ByVal | Call | Case | Catch | CBool |
CByte | CChar | CDate | CDec | CDbl | Char | CInt |
Class | CLng | CObj | Const | Continue | CSByte | CShort |
CSng | CStr | CType | CUInt | CULng | CUShort | Date |
Decimal | Declare | Default | Delegate | Dim | DirectCast | Do |
Double | Each | Else | ElseIf | End | End If | Enum |
Erase | Error | Event | Exit | False | Finally | For |
Friend | Function | Get | GetType | GetXML Namespace |
Global | GoTo |
Handles | If | Implements | Imports | In | Inherits | Integer |
Interface | Is | IsNot | Let | Lib | Like | Long |
Loop | Me | Mod | Module | MustInherit | MustOverride | MyBase |
MyClass | Namespace | Narrowing | New | Next | Not | Nothing |
Not Inheritable |
Not Overridable |
Object | Of | On | Operator | Option |
Optional | Or | OrElse | Overloads | Overridable | Overrides | ParamArray |
Partial | Private | Property | Protected | Public | RaiseEvent | ReadOnly |
ReDim | REM | Remove Handler |
Resume | Return | SByte | Select |
Set | Shadows | Shared | Short | Single | Static | Step |
Stop | String | Structure | Sub | SyncLock | Then | Throw |
To | True | Try | TryCast | TypeOf | UInteger | While |
Widening | With | WithEvents | WriteOnly | Xor |
Data Type | Storage Allocation | Value Range |
---|---|---|
Boolean | Depends on implementing platform | True or False |
Byte | 1 byte | 0 through 255 (unsigned) |
Char | 2 bytes | 0 through 65535 (unsigned) |
Date | 8 bytes | 0:00:00 (midnight) on January 1, 0001 through 11:59:59 PM on December 31, 9999 |
Decimal | 16 bytes | 0 through +/-79,228,162,514,264,337,593,543,950,335 (+/-7.9...E+28) with no decimal point; 0 through +/-7.9228162514264337593543950335 with 28 places to the right of the decimal |
Double | 8 bytes | -1.79769313486231570E+308 through -4.94065645841246544E-324, for negative values 4.94065645841246544E-324 through 1.79769313486231570E+308, for positive values |
Integer | 4 bytes | -2,147,483,648 through 2,147,483,647 (signed) |
Long | 8 bytes | -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807(signed) |
Object | 4 bytes on 32-bit platform 8 bytes on 64-bit platform |
Any type can be stored in a variable of type Object |
SByte | 1 byte | -128 through 127 (signed) |
Short | 2 bytes | -32,768 through 32,767 (signed) |
Single | 4 bytes | -3.4028235E+38 through -1.401298E-45 for negative values; 1.401298E-45 through 3.4028235E+38 for positive values |
String | Depends on implementing platform | 0 to approximately 2 billion Unicode characters |
UInteger | 4 bytes | 0 through 4,294,967,295 (unsigned) |
ULong | 8 bytes | 0 through 18,446,744,073,709,551,615 (unsigned) |
User-Defined | Depends on implementing platform | Each member of the structure has a range determined by its data type and independent of the ranges of the other members |
UShort | 2 bytes | 0 through 65,535 (unsigned) |
Module DataTypes Sub Main() Dim b As Byte Dim n As Integer Dim si As Single Dim d As Double Dim da As Date Dim c As Char Dim s As String Dim bl As Boolean b = 1 n = 1234567 si = 0.12345678901234566 d = 0.12345678901234566 da = Today c = "U"c s = "Me" If ScriptEngine = "VB" Then bl = True Else bl = False End If If bl Then 'the oath taking Console.Write(c & " and," & s & vbCrLf) Console.WriteLine("declaring on the day of: {0}", da) Console.WriteLine("We will learn VB.Net seriously") Console.WriteLine("Lets see what happens to the floating point variables:") Console.WriteLine("The Single: {0}, The Double: {1}", si, d) End If Console.ReadKey() End Sub End ModuleWhen the above code is compiled and executed, it produces the following result:
U and, Me declaring on the day of: 12/4/2012 12:00:00 PM We will learn VB.Net seriously Lets see what happens to the floating point variables: The Single:0.1234568, The Double: 0.123456789012346
S.N | Functions & Description |
---|---|
1 | CBool(expression) Converts the expression to Boolean data type. |
2 | CByte(expression) Converts the expression to Byte data type. |
3 | CChar(expression) Converts the expression to Char data type. |
4 | CDate(expression) Converts the expression to Date data type |
5 | CDbl(expression) Converts the expression to Double data type. |
6 | CDec(expression) Converts the expression to Decimal data type. |
7 | CInt(expression) Converts the expression to Integer data type. |
8 | CLng(expression) Converts the expression to Long data type. |
9 | CObj(expression) Converts the expression to Object type. |
10 | CSByte(expression) Converts the expression to SByte data type. |
11 | CShort(expression) Converts the expression to Short data type. |
12 | CSng(expression) Converts the expression to Single data type. |
13 | CStr(expression) Converts the expression to String data type. |
14 | CUInt(expression) Converts the expression to UInt data type. |
15 | CULng(expression) Converts the expression to ULng data type. |
16 | CUShort(expression) Converts the expression to UShort data type. |
Module DataTypes Sub Main() Dim n As Integer Dim da As Date Dim bl As Boolean = True n = 1234567 da = Today Console.WriteLine(bl) Console.WriteLine(CSByte(bl)) Console.WriteLine(CStr(bl)) Console.WriteLine(CStr(da)) Console.WriteLine(CChar(CChar(CStr(n)))) Console.WriteLine(CChar(CStr(da))) Console.ReadKey() End Sub End ModuleWhen the above code is compiled and executed, it produces the following result:
True -1 True 12/4/2012 1 1
Type | Example |
---|---|
Integral types | SByte, Byte, Short, UShort, Integer, UInteger, Long, ULong and Char |
Floating point types | Single and Double |
Decimal types | Decimal |
Boolean types | True or False values, as assigned |
Date types | Date |
[ < attributelist> ] [ accessmodifier ] [[ Shared ] [ Shadows ] | [ Static ]] [ ReadOnly ] Dim [ WithEvents ] variablelistWhere,
variablename[ ( [ boundslist ] ) ] [ As [ New ] datatype ] [ = initializer ]Where,
Dim StudentID As Integer Dim StudentName As String Dim Salary As Double Dim count1, count2 As Integer Dim status As Boolean Dim exitButton As New System.Windows.Forms.Button Dim lastTime, nextTime As Date
variable_name = value;for example,
Dim pi As Double pi = 3.14159You can initialize a variable at the time of declaration as follows:
Dim StudentID As Integer = 100 Dim StudentName As String = "Bill Smith"
Module variablesNdataypes Sub Main() Dim a As Short Dim b As Integer Dim c As Double a = 10 b = 20 c = a + b Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c) Console.ReadLine() End Sub End ModuleWhen the above code is compiled and executed, it produces the following result:
a = 10, b = 20, c = 30
Dim message As String message = Console.ReadLineThe following example demonstrates it:
Module variablesNdataypes Sub Main() Dim message As String Console.Write("Enter message: ") message = Console.ReadLine Console.WriteLine() Console.WriteLine("Your Message: {0}", message) Console.ReadLine() End Sub End ModuleWhen the above code is compiled and executed, it produces the following result (assume the user inputs Hello World):
Enter message: Hello World Your Message: Hello World
Dim g As Integer = 20But following is not a valid statement and would generate compile-time error:
20 = g
[ < attributelist> ] [ accessmodifier ] [ Shadows ] Const constantlistWhere,
constantname [ As datatype ] = initializer
' The following statements declare constants.
Const maxval As Long = 4999
Public Const message As String = "HELLO"
Private Const piValue As Double = 3.1415
Module constantsNenum Sub Main() Const PI = 3.14149 Dim radius, area As Single radius = 7 area = PI * radius * radius Console.WriteLine("Area = " & Str(area)) Console.ReadKey() End Sub End ModuleWhen the above code is compiled and executed, it produces the following result:
Area = 153.933
Constant | Description |
---|---|
vbCrLf | Carriage return/linefeed character combination. |
vbCr | Carriage return character. |
vbLf | Linefeed character. |
vbNewLine | Newline character. |
vbNullChar | Null character. |
vbNullString | Not the same as a zero-length string (""); used for calling external procedures. |
vbObjectError | Error number. User-defined error numbers should be greater than this value. For example: Err.Raise(Number) = vbObjectError + 1000 |
vbTab | Tab character. |
vbBack | Backspace character. |
[ < attributelist > ] [ accessmodifier ] [ Shadows ] Enum enumerationname [ As datatype ] memberlist End EnumWhere,
[< attribute list>] member name [ = initializer ]Where,
Enum Colors red = 1 orange = 2 yellow = 3 green = 4 azure = 5 blue = 6 violet = 7 End Enum
Module constantsNenum Enum Colors red = 1 orange = 2 yellow = 3 green = 4 azure = 5 blue = 6 violet = 7 End Enum Sub Main() Console.WriteLine("The Color Red is : " & Colors.red) Console.WriteLine("The Color Yellow is : " & Colors.yellow) Console.WriteLine("The Color Blue is : " & Colors.blue) Console.WriteLine("The Color Green is : " & Colors.green) Console.ReadKey() End Sub End ModuleWhen the above code is compiled and executed, it produces the following result:
The Color Red is: 1 The Color Yellow is: 3 The Color Blue is: 6 The Color Green is: 4
S.N | Modifier | Description |
---|---|---|
1 | Ansi | Specifies that Visual Basic should marshal all strings to American National Standards Institute (ANSI) values regardless of the name of the external procedure being declared. |
2 | Assembly | Specifies that an attribute at the beginning of a source file applies to the entire assembly. |
3 | Async | Indicates that the method or lambda expression that it modifies is asynchronous. Such methods are referred to as async methods. The caller of an async method can resume its work without waiting for the async method to finish. |
4 | Auto | The charsetmodifier part in the Declare statement supplies the character set information for marshaling strings during a call to the external procedure. It also affects how Visual Basic searches the external file for the external procedure name. The Auto modifier specifies that Visual Basic should marshal strings according to .NET Framework rules. |
5 | ByRef | Specifies that an argument is passed by reference, i.e., the called
procedure can change the value of a variable underlying the argument in
the calling code. It is used under the contexts of:
|
6 | ByVal | Specifies that an argument is passed in such a way that the called
procedure or property cannot change the value of a variable underlying
the argument in the calling code. It is used under the contexts of:
|
7 | Default | Identifies a property as the default property of its class, structure, or interface. |
8 | Friend | Specifies that one or more declared programming elements are
accessible from within the assembly that contains their declaration, not
only by the component that declares them. Friend access is often the preferred level for an application's programming elements, and Friend is the default access level of an interface, a module, a class, or a structure. |
9 | In | It is used in generic interfaces and delegates. |
10 | Iterator | Specifies that a function or Get accessor is an iterator. An iterator performs a custom iteration over a collection. |
11 | Key | The Key keyword enables you to specify behavior for properties of anonymous types. |
12 | Module | Specifies that an attribute at the beginning of a source file applies to the current assembly module. It is not same as the Module statement. |
13 | MustInherit | Specifies that a class can be used only as a base class and that you cannot create an object directly from it. |
14 | MustOverride | Specifies that a property or procedure is not implemented in this class and must be overridden in a derived class before it can be used. |
15 | Narrowing | Indicates that a conversion operator (CType) converts a class or structure to a type that might not be able to hold some of the possible values of the original class or structure. |
16 | NotInheritable | Specifies that a class cannot be used as a base class. |
17 | NotOverridable | Specifies that a property or procedure cannot be overridden in a derived class. |
18 | Optional | Specifies that a procedure argument can be omitted when the procedure is called. |
19 | Out | For generic type parameters, the Out keyword specifies that the type is covariant. |
20 | Overloads | Specifies that a property or procedure redeclares one or more existing properties or procedures with the same name. |
21 | Overridable | Specifies that a property or procedure can be overridden by an identically named property or procedure in a derived class. |
22 | Overrides | Specifies that a property or procedure overrides an identically named property or procedure inherited from a base class. |
23 | ParamArray | ParamArray allows you to pass an arbitrary number of arguments to the procedure. A ParamArray parameter is always declared using ByVal. |
24 | Partial | Indicates that a class or structure declaration is a partial definition of the class or structure. |
25 | Private | Specifies that one or more declared programming elements are accessible only from within their declaration context, including from within any contained types. |
26 | Protected | Specifies that one or more declared programming elements are accessible only from within their own class or from a derived class. |
27 | Public | Specifies that one or more declared programming elements have no access restrictions. |
28 | ReadOnly | Specifies that a variable or property can be read but not written. |
29 | Shadows | Specifies that a declared programming element redeclares and hides an identically named element, or set of overloaded elements, in a base class. |
30 | Shared | Specifies that one or more declared programming elements are associated with a class or structure at large, and not with a specific instance of the class or structure. |
31 | Static | Specifies that one or more declared local variables are to continue to exist and retain their latest values after termination of the procedure in which they are declared. |
32 | Unicode | Specifies that Visual Basic should marshal all strings to Unicode values regardless of the name of the external procedure being declared. |
33 | Widening | Indicates that a conversion operator (CType) converts a class or structure to a type that can hold all possible values of the original class or structure. |
34 | WithEvents | Specifies that one or more declared member variables refer to an instance of a class that can raise events. |
35 | WriteOnly | Specifies that a property can be written but not read. |
S.N | Statements and Description | Example |
---|---|---|
1 | Dim Statement Declares and allocates storage space for one or more variables. |
Dim number As Integer Dim quantity As Integer = 100 Dim message As String = "Hello!" |
2 | Const Statement Declares and defines one or more constants. |
Const maximum As Long = 1000 Const naturalLogBase As Object = CDec(2.7182818284) |
3 | Enum Statement
Declares an enumeration and defines the values of its members. |
Enum CoffeeMugSize Jumbo ExtraLarge Large Medium Small End Enum |
4 | Class Statement Declares the name of a class and introduces the definition of the variables, properties, events, and procedures that the class comprises. |
Class Box Public length As Double Public breadth As Double Public height As Double End Class |
5 | Structure Statement Declares the name of a structure and introduces the definition of the variables, properties, events, and procedures that the structure comprises. |
Structure Box Public length As Double Public breadth As Double Public height As Double End Structure |
6 | Module Statement Declares the name of a module and introduces the definition of the variables, properties, events, and procedures that the module comprises. |
Public Module myModule Sub Main() Dim user As String = InputBox("What is your name?") MsgBox("User name is" & user) End Sub End Module |
7 | Interface Statement Declares the name of an interface and introduces the definitions of the members that the interface comprises. |
Public Interface MyInterface Sub doSomething() End Interface |
8 | Function Statement Declares the name, parameters, and code that define a Function procedure. |
Function myFunction (ByVal n As Integer) As Double Return 5.87 * n End Function |
9 | Sub Statement Declares the name, parameters, and code that define a Sub procedure. |
Sub mySub(ByVal s As String) Return End Sub |
10 | Declare Statement Declares a reference to a procedure implemented in an external file. |
Declare Function getUserName Lib "advapi32.dll" Alias "GetUserNameA" ( ByVal lpBuffer As String, ByRef nSize As Integer) As Integer |
11 | Operator Statement Declares the operator symbol, operands, and code that define an operator procedure on a class or structure. |
Public Shared Operator + (ByVal x As obj, ByVal y As obj) As obj Dim r As New obj ' implemention code for r = x + y Return r End Operator |
12 | Property Statement Declares the name of a property, and the property procedures used to store and retrieve the value of the property. |
ReadOnly Property quote() As String Get Return quoteString End Get End Property |
13 | Event Statement Declares a user-defined event. |
Public Event Finished() |
14 | Delegate Statement Used to declare a delegate. |
Delegate Function MathOperator( ByVal x As Double, ByVal y As Double ) As Double |
Module decisions Sub Main() 'local variable definition ' Dim a As Integer = 10 ' check the boolean condition using if statement ' If (a < 20) Then ' if condition is true then print the following ' Console.WriteLine("a is less than 20") End If Console.WriteLine("value of a is : {0}", a) Console.ReadLine() End Sub End ModuleWhen the above code is compiled and executed, it produces the following result:
a is less than 20; value of a is : 10
#Const constname = expression
Where,#Const state = "WEST BENGAL"
ExampleModule mydirectives #Const age = True Sub Main() #If age Then Console.WriteLine("You are welcome to the Robotics Club") #End If Console.ReadKey() End Sub End ModuleWhen the above code is compiled and executed, it produces the following result:
You are welcome to the Robotics Club
#ExternalSource( StringLiteral , IntLiteral ) [ LogicalLine ] #End ExternalSourceThe parameters of #ExternalSource directive are the path of external file, line number of the first line, and the line where the error occurred.
Module mydirectives Public Class ExternalSourceTester Sub TestExternalSource() #ExternalSource("c:\vbprogs\directives.vb", 5) Console.WriteLine("This is External Code. ") #End ExternalSource End Sub End Class Sub Main() Dim t As New ExternalSourceTester() t.TestExternalSource() Console.WriteLine("In Main.") Console.ReadKey() End SubWhen the above code is compiled and executed, it produces the following result:
This is External Code. In Main.
#If expression Then statements [ #ElseIf expression Then [ statements ] ... #ElseIf expression Then [ statements ] ] [ #Else [ statements ] ] #End IfFor example,
#Const TargetOS = "Linux" #If TargetOS = "Windows 7" Then ' Windows 7 specific code #ElseIf TargetOS = "WinXP" Then ' Windows XP specific code #Else ' Code for other OS #End ifExample
Module mydirectives #Const classCode = 8 Sub Main() #If classCode = 7 Then Console.WriteLine("Exam Questions for Class VII") #ElseIf classCode = 8 Then Console.WriteLine("Exam Questions for Class VIII") #Else Console.WriteLine("Exam Questions for Higher Classes") #End If Console.ReadKey() End Sub End ModuleWhen the above code is compiled and executed, it produces the following result:
Exam Questions for Class VIII
#Region "identifier_string" #End RegionFor example,
#Region "StatsFunctions" ' Insert code for the Statistical functions here. #End Region
Operator | Description | Example |
---|---|---|
^ | Raises one operand to the power of another | B^A will give 49 |
+ | Adds two operands | A + B will give 9 |
- | Subtracts second operand from the first | A - B will give -5 |
* | Multiplies both operands | A * B will give 14 |
/ | Divides one operand by another and returns a floating point result | B / A will give 3.5 |
\ | Divides one operand by another and returns an integer result | B \ A will give 3 |
MOD | Modulus Operator and remainder of after an integer division | B MOD A will give 1 |
Operator | Description | Example |
---|---|---|
= | Checks if the values of two operands are equal or not; if yes, then condition becomes true. | (A = B) is not true. |
<> | Checks if the values of two operands are equal or not; if values are not equal, then condition becomes true. | (A <> B) is true. |
> | Checks if the value of left operand is greater than the value of right operand; if yes, then condition becomes true. | (A > B) is not true. |
< | Checks if the value of left operand is less than the value of right operand; if yes, then condition becomes true. | (A < B) is true. |
>= | Checks if the value of left operand is greater than or equal to the value of right operand; if yes, then condition becomes true. | (A >= B) is not true. |
<= | Checks if the value of left operand is less than or equal to the value of right operand; if yes, then condition becomes true. | (A <= B) is true. |
Operator | Description | Example |
---|---|---|
And | It is the logical as well as bitwise AND operator. If both the operands are true, then condition becomes true. This operator does not perform short-circuiting, i.e., it evaluates both the expressions. | (A And B) is False. |
Or | It is the logical as well as bitwise OR operator. If any of the two operands is true, then condition becomes true. This operator does not perform short-circuiting, i.e., it evaluates both the expressions. | (A Or B) is True. |
Not | It is the logical as well as bitwise NOT operator. Use to reverses the logical state of its operand. If a condition is true, then Logical NOT operator will make false. | Not(A And B) is True. |
Xor | It is the logical as well as bitwise Logical Exclusive OR operator. It returns True if both expressions are True or both expressions are False; otherwise it returns False. This operator does not perform short-circuiting, it always evaluates both expressions and there is no short-circuiting counterpart of this operator. | A Xor B is True. |
AndAlso | It is the logical AND operator. It works only on Boolean data. It performs short-circuiting. | (A AndAlso B) is False. |
OrElse | It is the logical OR operator. It works only on Boolean data. It performs short-circuiting. | (A OrElse B) is True. |
IsFalse | It determines whether an expression is False. | |
IsTrue | It determines whether an expression is True. |
p | q | p & q | p | q | p ^ q |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 | 1 |
1 | 1 | 1 | 1 | 0 |
1 | 0 | 0 | 1 | 1 |
Operator | Description | Example |
---|---|---|
And | Bitwise AND Operator copies a bit to the result if it exists in both operands. | (A AND B) will give 12, which is 0000 1100 |
Or | Binary OR Operator copies a bit if it exists in either operand. | (A Or B) will give 61, which is 0011 1101 |
Xor | Binary XOR Operator copies the bit if it is set in one operand but not both. | (A Xor B) will give 49, which is 0011 0001 |
Not | Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. | (Not A ) will give -61, which is 1100 0011 in 2's complement form due to a signed binary number. |
<< | Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. | A << 2 will give 240, which is 1111 0000 |
>> | Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. | A >> 2 will give 15, which is 0000 1111 |
Operator | Description | Example |
---|---|---|
= | Simple assignment operator, Assigns values from right side operands to left side operand | C = A + B will assign value of A + B into C |
+= | Add AND assignment operator, It adds right operand to the left operand and assigns the result to left operand | C += A is equivalent to C = C + A |
-= | Subtract AND assignment operator, It subtracts right operand from the left operand and assigns the result to left operand | C -= A is equivalent to C = C - A |
*= | Multiply AND assignment operator, It multiplies right operand with the left operand and assigns the result to left operand | C *= A is equivalent to C = C * A |
/= | Divide AND assignment operator, It divides left operand with the right operand and assigns the result to left operand (floating point division) | C /= A is equivalent to C = C / A |
\= | Divide AND assignment operator, It divides left operand with the right operand and assigns the result to left operand (Integer division) | C \= A is equivalent to C = C \A |
^= | Exponentiation and assignment operator. It raises the left operand to the power of the right operand and assigns the result to left operand. | C^=A is equivalent to C = C ^ A |
<<= | Left shift AND assignment operator | C <<= 2 is same as C = C << 2 |
>>= | Right shift AND assignment operator | C >>= 2 is same as C = C >> 2 |
&= | Concatenates a String expression to a String variable or property and assigns the result to the variable or property. | Str1 &= Str2 is same as Str1 = Str1 & Str2 |
Operator | Description | Example |
---|---|---|
AddressOf | Returns the address of a procedure. | AddHandler Button1.Click, AddressOf Button1_Click |
Await | It is applied to an operand in an asynchronous method or lambda expression to suspend execution of the method until the awaited task completes. | Dim result As res = Await AsyncMethodThatReturnsResult() Await AsyncMethod() |
GetType | It returns a Type object for the specified type. The Type object provides information about the type such as its properties, methods, and events. | MsgBox(GetType(Integer).ToString()) |
Function Expression | It declares the parameters and code that define a function lambda expression. | Dim add5 = Function(num As Integer) num + 5 'prints 10 Console.WriteLine(add5(5)) |
If | It uses short-circuit evaluation to conditionally return one of two values. The If operator can be called with three arguments or with two arguments. | Dim num = 5 Console.WriteLine(If(num >= 0, "Positive", "Negative")) |
Operator | Precedence |
---|---|
Await | Highest |
Exponentiation (^) | |
Unary identity and negation (+, -) | |
Multiplication and floating-point division (*, /) | |
Integer division (\) | |
Modulus arithmetic (Mod) | |
Addition and subtraction (+, -) | |
Arithmetic bit shift (<<, >>) | |
All comparison operators (=, <>, <, <=, >, >=, Is, IsNot, Like, TypeOf...Is) | |
Negation (Not) | |
Conjunction (And, AndAlso) | |
Inclusive disjunction (Or, OrElse) | |
Exclusive disjunction (Xor) | Lowest |