0% found this document useful (0 votes)
25 views11 pages

Lecture Two

The document discusses constants and operators in VB.Net. Constants refer to fixed values that cannot change during program execution and can be of basic data types. Constants are declared using Const and can be at various scopes. The document also covers arithmetic, comparison, and logical operators and provides examples of their usage.

Uploaded by

David Ezekiel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views11 pages

Lecture Two

The document discusses constants and operators in VB.Net. Constants refer to fixed values that cannot change during program execution and can be of basic data types. Constants are declared using Const and can be at various scopes. The document also covers arithmetic, comparison, and logical operators and provides examples of their usage.

Uploaded by

David Ezekiel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

VB.

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 −

constantname [ As datatype ] = initializer

For example,

Const maxval As Long = 4999


Public Const message As String = "HELLO"
Private Const piValue As Double = 3.1415
VB.Net - Operators 3

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

- 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 B / A will give 3.5
point result

\ Divides one operand by another and returns an integer B \ A will give 3


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

= Checks if the values of two operands (A = B) is not true.


are equal or not; if yes, then
condition becomes true.

<> Checks if the values of two operands (A <> B) is true.


are equal or not; if values are not
equal, then condition becomes true.

> Checks if the value of left operand is (A > B) is not true.


greater than the value of right
operand; if yes, then condition
becomes true.
< Checks if the value of left operand is (A < B) is true.
less than the value of right operand;
if yes, then condition becomes true.

>= Checks if the value of left operand is (A >= B) is not true.


greater than or equal to the value of
right operand; if yes, then condition
becomes true.

<= Checks if the value of left operand is (A <= B) is true.


less than or equal to the value of
right operand; if yes, then condition
becomes true.
VISUAL BASIC IF STATEMENT 7
In Visual Basic, If statement is useful to execute the block of code or statements conditionally based on the
value of an expression.

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.

Syntax of Visual Basic if Statement


Following is the syntax of defining the if statement in Visual Basic programming language.

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

Following is the sample example of using the If statement in Visual Basic


programming language.

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

Following is the example of defining the If statement in Visual Basic programming


language to execute the block of code or statements based on a Boolean
expression.

You might also like