SlideShare a Scribd company logo
Lesson 3 of 8 Visual Basic Programming
1 of 4
Lesson 3: Conditional Logic
Author: Kasun Ranga Wijeweera
Email: krw19870829@gmail.com
Date: 2020 April 29
Look at the code segment given below.
Dim x, y As Integer
x = 5
y = 5
If x = y Then MessageBox.Show (“Equal”)
Execution of the above code segment displays a message box
with text “Equal”.
The equals sign shown in red color works as the Equality
Operator. If the value of x equals to the value of y then the code
fragment x = y returns True. Otherwise the code fragment returns
False.
If…Then statement was used in the code segment above. A
<<condition>> should be written between If and Then parts. The
code fragment in the right side of the Then part is executed only if the
<<condition>> returns True.
Now look at the code segment given below.
Dim x, y As Integer
x = 5
Lesson 3 of 8 Visual Basic Programming
2 of 4
y = 6
If x = y Then MessageBox.Show (“Equal”)
Execution of the above code segment does not display the
message box as the <<condition>> returns False.
Only a single line of code can be included after Then part when
using If…Then statement. Therefore, If…Then…End If statement
should be used in order to have more than a single line of code after
Then part. Now look at the code segment given below.
Dim x, y As Integer
x = 5
y = 5
If x = y Then
MessageBox.Show (“Equal”)
MessageBox.Show (“x is equal to y”)
End If
Execution of the above code segment displays two message
boxes each with texts “Equal” and “x is equal to y” respectively.
Look at the code segment given below that demonstrates the usage of
If…Then…Else statement.
Dim x, y As Integer
x = 5
y = 5
Lesson 3 of 8 Visual Basic Programming
3 of 4
If x = y Then MessageBox.Show (“Y”) Else MessageBox.Show (“N”)
Execution of the above code displays “Y” in a message box
since the condition is true. Execution of the code given below
displays “N” in a message box since the condition is false.
Dim x, y As Integer
x = 5
y = 6
If x = y Then MessageBox.Show (“Y”) Else MessageBox.Show (“N”)
If…Then…Else…End If statement should be used when there
are more than a single line of code to execute if the condition is either
true or false. Look at the code segment given below.
Dim x, y As Integer
x = 5
y = 5
If x = y Then
MessageBox.Show (“Equal”)
MessageBox.Show (“x is equal to y”)
Else
MessageBox.Show (“Not equal”)
MessageBox.Show (“x is not equal to y”)
End If
Execution of the above code displays two message boxes each
with texts “Equal” and “x is equal to y” respectively as the condition
is true. Now look at the code segment given below.
Lesson 3 of 8 Visual Basic Programming
4 of 4
Dim x, y As Integer
x = 5
y = 6
If x = y Then
MessageBox.Show (“Equal”)
MessageBox.Show (“x is equal to y”)
Else
MessageBox.Show (“Not equal”)
MessageBox.Show (“x is not equal to y”)
End If
Execution of the above code segment displays two message
boxes with texts “Not equal” and “x is not equal to y” respectively as
the condition is false.
If…Then…ElseIf…Else…End If statement can be used when
there are multiple conditions. Look at the code segment given below.
Dim x As Integer = 18.76
If x < 10 Then
MessageBox.Show (“x < 10”)
ElseIf x < 20 Then
MessageBox.Show (“10 <= x < 20”)
ElseIf x < 30 Then
MessageBox.Show (“20 <= x < 30”)
Else
MessageBox.Show (“x >= 30”)
End If

More Related Content

What's hot

Data types and operators in vb
Data types and operators  in vbData types and operators  in vb
Data types and operators in vb
alldesign
 
Uncertainty in Geospatial Data
Uncertainty in Geospatial DataUncertainty in Geospatial Data
Uncertainty in Geospatial Data
Ehsan Hamzei
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
Soran University
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
University of Potsdam
 
Operator Precedence and Associativity
Operator Precedence and AssociativityOperator Precedence and Associativity
Operator Precedence and Associativity
Nicole Ynne Estabillo
 
Operators
OperatorsOperators
Flowchart pseudocode-examples
Flowchart pseudocode-examplesFlowchart pseudocode-examples
Flowchart pseudocode-examples
Gautam Roy
 
Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programming
Dhrumil Panchal
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basicsrobertbenard
 
CPU
CPUCPU
Lesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbersLesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbers
PVS-Studio
 
Object oriented programming16 boolean expressions and selection statements
Object oriented programming16 boolean expressions and selection statementsObject oriented programming16 boolean expressions and selection statements
Object oriented programming16 boolean expressions and selection statements
Vaibhav Khanna
 
Pseudocode
PseudocodePseudocode
Pseudocode
Guy09
 
Zero to ECC in 30 Minutes: A primer on Elliptic Curve Cryptography (ECC)
Zero to ECC in 30 Minutes: A primer on Elliptic Curve Cryptography (ECC)Zero to ECC in 30 Minutes: A primer on Elliptic Curve Cryptography (ECC)
Zero to ECC in 30 Minutes: A primer on Elliptic Curve Cryptography (ECC)
Entrust Datacard
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01
Drjilesh
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
baabtra.com - No. 1 supplier of quality freshers
 

What's hot (19)

Data types and operators in vb
Data types and operators  in vbData types and operators  in vb
Data types and operators in vb
 
Uncertainty in Geospatial Data
Uncertainty in Geospatial DataUncertainty in Geospatial Data
Uncertainty in Geospatial Data
 
Guess a number game
Guess a number gameGuess a number game
Guess a number game
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
Decisions
DecisionsDecisions
Decisions
 
Operator Precedence and Associativity
Operator Precedence and AssociativityOperator Precedence and Associativity
Operator Precedence and Associativity
 
Operators
OperatorsOperators
Operators
 
Flowchart pseudocode-examples
Flowchart pseudocode-examplesFlowchart pseudocode-examples
Flowchart pseudocode-examples
 
Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programming
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
 
CPU
CPUCPU
CPU
 
Lesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbersLesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbers
 
Object oriented programming16 boolean expressions and selection statements
Object oriented programming16 boolean expressions and selection statementsObject oriented programming16 boolean expressions and selection statements
Object oriented programming16 boolean expressions and selection statements
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
Macros
MacrosMacros
Macros
 
Zero to ECC in 30 Minutes: A primer on Elliptic Curve Cryptography (ECC)
Zero to ECC in 30 Minutes: A primer on Elliptic Curve Cryptography (ECC)Zero to ECC in 30 Minutes: A primer on Elliptic Curve Cryptography (ECC)
Zero to ECC in 30 Minutes: A primer on Elliptic Curve Cryptography (ECC)
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 

Similar to Conditional Logic in Visual Basic Programming

Unit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptxUnit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptx
Ujwala Junghare
 
Visual basic bt0082
Visual basic  bt0082Visual basic  bt0082
Visual basic bt0082
Divyam Pateriya
 
Pseudocode By ZAK
Pseudocode By ZAKPseudocode By ZAK
Pseudocode By ZAK
Tabsheer Hasan
 
A01
A01A01
A01
lksoo
 
Lập Trình VBA For Excel Tại Biên Hòa
Lập Trình VBA For Excel Tại Biên HòaLập Trình VBA For Excel Tại Biên Hòa
Lập Trình VBA For Excel Tại Biên Hòa
Trần Đình Ngọc
 
Excel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA Learning
Excel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA LearningExcel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA Learning
Excel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA Learning
PrantikMaity6
 
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
Suraj Kumar
 
Working with comparison operators
Working with comparison operatorsWorking with comparison operators
Working with comparison operatorsSara Corpuz
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selection
Hamad Odhabi
 
Ejp 01
Ejp 01Ejp 01
C Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.pptC Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.ppt
GAURAVNAUTIYAL19
 
Spss guideline
Spss guidelineSpss guideline
Spss guidelineASDFGGK
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basicsrobertbenard
 
Useful macros and functions for excel
Useful macros and functions for excelUseful macros and functions for excel
Useful macros and functions for excel
Nihar Ranjan Paital
 
Fin 351Project 2Derivation of the Efficient Frontier Part .docx
Fin 351Project 2Derivation of the Efficient Frontier Part .docxFin 351Project 2Derivation of the Efficient Frontier Part .docx
Fin 351Project 2Derivation of the Efficient Frontier Part .docx
mydrynan
 
04 Conditions.pptx
04 Conditions.pptx04 Conditions.pptx
04 Conditions.pptx
GovandZangana
 

Similar to Conditional Logic in Visual Basic Programming (18)

Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Unit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptxUnit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptx
 
Visual basic bt0082
Visual basic  bt0082Visual basic  bt0082
Visual basic bt0082
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Pseudocode By ZAK
Pseudocode By ZAKPseudocode By ZAK
Pseudocode By ZAK
 
A01
A01A01
A01
 
Lập Trình VBA For Excel Tại Biên Hòa
Lập Trình VBA For Excel Tại Biên HòaLập Trình VBA For Excel Tại Biên Hòa
Lập Trình VBA For Excel Tại Biên Hòa
 
Excel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA Learning
Excel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA LearningExcel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA Learning
Excel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA Learning
 
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
 
Working with comparison operators
Working with comparison operatorsWorking with comparison operators
Working with comparison operators
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selection
 
Ejp 01
Ejp 01Ejp 01
Ejp 01
 
C Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.pptC Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.ppt
 
Spss guideline
Spss guidelineSpss guideline
Spss guideline
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
 
Useful macros and functions for excel
Useful macros and functions for excelUseful macros and functions for excel
Useful macros and functions for excel
 
Fin 351Project 2Derivation of the Efficient Frontier Part .docx
Fin 351Project 2Derivation of the Efficient Frontier Part .docxFin 351Project 2Derivation of the Efficient Frontier Part .docx
Fin 351Project 2Derivation of the Efficient Frontier Part .docx
 
04 Conditions.pptx
04 Conditions.pptx04 Conditions.pptx
04 Conditions.pptx
 

More from Kasun Ranga Wijeweera

Decorator Design Pattern in C#
Decorator Design Pattern in C#Decorator Design Pattern in C#
Decorator Design Pattern in C#
Kasun Ranga Wijeweera
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#Singleton Design Pattern in C#
Singleton Design Pattern in C#
Kasun Ranga Wijeweera
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
Kasun Ranga Wijeweera
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
Kasun Ranga Wijeweera
 
Geometric Transformations II
Geometric Transformations IIGeometric Transformations II
Geometric Transformations II
Kasun Ranga Wijeweera
 
Geometric Transformations I
Geometric Transformations IGeometric Transformations I
Geometric Transformations I
Kasun Ranga Wijeweera
 
Introduction to Polygons
Introduction to PolygonsIntroduction to Polygons
Introduction to Polygons
Kasun Ranga Wijeweera
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: ExercisesLoops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
Kasun Ranga Wijeweera
 
Conditional Logic: Exercises
Conditional Logic: ExercisesConditional Logic: Exercises
Conditional Logic: Exercises
Kasun Ranga Wijeweera
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
Kasun Ranga Wijeweera
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtonsCheckBoxes and RadioButtons
CheckBoxes and RadioButtons
Kasun Ranga Wijeweera
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic Programming
Kasun Ranga Wijeweera
 
Loops in Visual Basic Programming
Loops in Visual Basic ProgrammingLoops in Visual Basic Programming
Loops in Visual Basic Programming
Kasun Ranga Wijeweera
 
Assignment for Variables
Assignment for VariablesAssignment for Variables
Assignment for Variables
Kasun Ranga Wijeweera
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Kasun Ranga Wijeweera
 
Assignment for Events
Assignment for EventsAssignment for Events
Assignment for Events
Kasun Ranga Wijeweera
 
Mastering Arrays Assignment
Mastering Arrays AssignmentMastering Arrays Assignment
Mastering Arrays Assignment
Kasun Ranga Wijeweera
 
Arrays in Visual Basic Programming
Arrays in Visual Basic ProgrammingArrays in Visual Basic Programming
Arrays in Visual Basic Programming
Kasun Ranga Wijeweera
 

More from Kasun Ranga Wijeweera (20)

Decorator Design Pattern in C#
Decorator Design Pattern in C#Decorator Design Pattern in C#
Decorator Design Pattern in C#
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#Singleton Design Pattern in C#
Singleton Design Pattern in C#
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
 
Geometric Transformations II
Geometric Transformations IIGeometric Transformations II
Geometric Transformations II
 
Geometric Transformations I
Geometric Transformations IGeometric Transformations I
Geometric Transformations I
 
Introduction to Polygons
Introduction to PolygonsIntroduction to Polygons
Introduction to Polygons
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: ExercisesLoops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
 
Conditional Logic: Exercises
Conditional Logic: ExercisesConditional Logic: Exercises
Conditional Logic: Exercises
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtonsCheckBoxes and RadioButtons
CheckBoxes and RadioButtons
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic Programming
 
Loops in Visual Basic Programming
Loops in Visual Basic ProgrammingLoops in Visual Basic Programming
Loops in Visual Basic Programming
 
Assignment for Variables
Assignment for VariablesAssignment for Variables
Assignment for Variables
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
 
Assignment for Events
Assignment for EventsAssignment for Events
Assignment for Events
 
Mastering Arrays Assignment
Mastering Arrays AssignmentMastering Arrays Assignment
Mastering Arrays Assignment
 
Arrays in Visual Basic Programming
Arrays in Visual Basic ProgrammingArrays in Visual Basic Programming
Arrays in Visual Basic Programming
 

Recently uploaded

Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 

Recently uploaded (20)

Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 

Conditional Logic in Visual Basic Programming

  • 1. Lesson 3 of 8 Visual Basic Programming 1 of 4 Lesson 3: Conditional Logic Author: Kasun Ranga Wijeweera Email: krw19870829@gmail.com Date: 2020 April 29 Look at the code segment given below. Dim x, y As Integer x = 5 y = 5 If x = y Then MessageBox.Show (“Equal”) Execution of the above code segment displays a message box with text “Equal”. The equals sign shown in red color works as the Equality Operator. If the value of x equals to the value of y then the code fragment x = y returns True. Otherwise the code fragment returns False. If…Then statement was used in the code segment above. A <<condition>> should be written between If and Then parts. The code fragment in the right side of the Then part is executed only if the <<condition>> returns True. Now look at the code segment given below. Dim x, y As Integer x = 5
  • 2. Lesson 3 of 8 Visual Basic Programming 2 of 4 y = 6 If x = y Then MessageBox.Show (“Equal”) Execution of the above code segment does not display the message box as the <<condition>> returns False. Only a single line of code can be included after Then part when using If…Then statement. Therefore, If…Then…End If statement should be used in order to have more than a single line of code after Then part. Now look at the code segment given below. Dim x, y As Integer x = 5 y = 5 If x = y Then MessageBox.Show (“Equal”) MessageBox.Show (“x is equal to y”) End If Execution of the above code segment displays two message boxes each with texts “Equal” and “x is equal to y” respectively. Look at the code segment given below that demonstrates the usage of If…Then…Else statement. Dim x, y As Integer x = 5 y = 5
  • 3. Lesson 3 of 8 Visual Basic Programming 3 of 4 If x = y Then MessageBox.Show (“Y”) Else MessageBox.Show (“N”) Execution of the above code displays “Y” in a message box since the condition is true. Execution of the code given below displays “N” in a message box since the condition is false. Dim x, y As Integer x = 5 y = 6 If x = y Then MessageBox.Show (“Y”) Else MessageBox.Show (“N”) If…Then…Else…End If statement should be used when there are more than a single line of code to execute if the condition is either true or false. Look at the code segment given below. Dim x, y As Integer x = 5 y = 5 If x = y Then MessageBox.Show (“Equal”) MessageBox.Show (“x is equal to y”) Else MessageBox.Show (“Not equal”) MessageBox.Show (“x is not equal to y”) End If Execution of the above code displays two message boxes each with texts “Equal” and “x is equal to y” respectively as the condition is true. Now look at the code segment given below.
  • 4. Lesson 3 of 8 Visual Basic Programming 4 of 4 Dim x, y As Integer x = 5 y = 6 If x = y Then MessageBox.Show (“Equal”) MessageBox.Show (“x is equal to y”) Else MessageBox.Show (“Not equal”) MessageBox.Show (“x is not equal to y”) End If Execution of the above code segment displays two message boxes with texts “Not equal” and “x is not equal to y” respectively as the condition is false. If…Then…ElseIf…Else…End If statement can be used when there are multiple conditions. Look at the code segment given below. Dim x As Integer = 18.76 If x < 10 Then MessageBox.Show (“x < 10”) ElseIf x < 20 Then MessageBox.Show (“10 <= x < 20”) ElseIf x < 30 Then MessageBox.Show (“20 <= x < 30”) Else MessageBox.Show (“x >= 30”) End If