Lecture Two
Lecture Two
Net - Constants 1
The constants refer to fixed values that the program may not alter during its
execution. These fixed values are also called literals.
Constants can be of any of the basic data types like an integer constant, a
floating constant, a character constant, or a string literal. There are also
enumeration constants as well.
The constants are treated just like regular variables except that their values
cannot be modified after their definition.
Declaring Constants 2
In VB.Net, constants are declared using the Const statement. The Const statement is used at module,
class, structure, procedure, or block level for use in place of literal values.
Where, each constant name has the following syntax and parts −
For example,
In Visual Basic, Operator is a programming element that specifies what operation needs to perform
on operands or variables. For example, an addition (+) operator in Visual Basic is used to perform
the sum operation on operands.
VB.Net is rich in built-in operators and provides following types of commonly used operators −Some
are as follows:
Arithmetic Operators
Following table shows all the arithmetic operators supported by VB.Net. Assume variable A holds 2
and variable B holds 7, then −
Operator Description Example
^ Raises one operand to the power of another B^A will give 49
4
+ Adds two operands A + B will give 9
/ Divides one operand by another and returns a floating B / A will give 3.5
point result
MOD Modulus Operator and remainder of after an integer B MOD A will give 1
division
Comparison Operators 5
Following table shows all the comparison operators supported by VB.Net. Assume
variable A holds 10 and variable B holds 20, then −
Comparison Operators
6
Operator Description Example
Generally, in Visual Basic, the statement that needs to be executed based on the condition is known as a
“Conditional Statement” and the statement is more likely a block of code.
If bool_expression Then
// Statements to Execute if condition is true
End If
If you observe the above If statement syntax, the statements inside of the If condition will be executed only
when the “bool_expression” returns true otherwise, those statements will be ignored for execution.
VISUAL BASIC IF STATEMENT 8
If you observe the above example, the Console statement will be executed only when the defined
condition (x >= 10) returns true.
Visual Basic If Statement Flow Chart
9
Diagram
Following is the flow chart diagram, which will represent the process flow of the If statement in Visual Basic
programming language.
Visual Basic If Statement Flow Chart
10
Diagram
If you observe the above Visual Basic If statement flow chart diagram, when the
defined condition is true, the statements within the If condition will be executed;
otherwise, the If condition will end without executing the statements.
Visual Basic If Statement Example 11