SlideShare a Scribd company logo
1 of 26
Module 7
Created by S. O’Brien-Duke
Logical
Operators
• Boolean Expressions
• Evaluates to True or False
• Can be formed using the logical
operator And and Or
• And
• Expression evaluates to True only
when both expressions (conditions)
are True
• If intGrade > 0 And intGrade < 100
Then
Me.lblDisplay.Text = “Valid
grade.”
Logical Operators
And
Expression 1
intGrade > 0
Expression 2
intGrade < 100
Result
Valid grade.
True True True
True False False
False True False
False False False
Logical
Operators
• Or
• If either expression (condition) is
true, then the entire expression is
True.
• If intGuess < 1 Or IntGuess> 50
Then
Me.lblMessage.Text = “Invalid
number”.
Logical Operators
Or
Expression 1
intGuess < 1
Expression 2
IntGuess> 50
Result
Invalid number
True True True
True False False
False True False
False False False
Logical
Operators
• Not
• Is True only when the expression it
is used with is False
• Example:
• strItem = “Pen”
• If Not strItem = “Pen” Then
Me.lblMessage.Text = “No
discount”.
• Would evaluate to False since
strItem does equal “Pen”
Logical Operators
Not
Expression
strItem = “Pen”
Result
No discount
True False
False True
Generating
Random
Numbers
• Random numbers are needed for
games, screen savers, and many other
types of applications.
• VB.NET has a built in Rnd() function
that generates random numbers.
• Using Rnd() alone generates number
greater than or equal to zero (0) and
less than one (1)
• What if a random number between 0
and 10 is needed?
Generating
Random
Numbers
• A range can be specified using this
formula
• (HighNumber – LowNumber + 1) *
Rnd() + LowNumber
• Example:
• We need a random number
between 10 and 30
• ((30-10+1 ) * Rnd() + 10)
• 21 * Rnd() + 10
• Using this formula we will have a
decimal number…Why?
Generating
Random
Numbers
• Rnd() generates number greater than or
equal to zero (0) and less than one (1)
• Rnd() always generates a decimal
• To generate an integer, the Int() function
can be used
• Int(21 * Rnd()) + 10
• The decimal potion of the calculation
is truncated
• Randomize()
• Initializes the Rnd() function
• Randomize() statement is added to the
event procedure before the Rnd()
function is used
Static Variables
• Variables have scope
• Local scope – declared in a
procedure
• Called a local variable
• Global scope – declared outside of
the procedure
• Called a global variable
• Variables also have a lifetime
• Local variable lifetime – duration of
the procedure
• Global variable lifetime – duration
of the program
Static Variables
• Lifetime of a local variable can be
extended by using a Static declaration
statement
• Static variableName as dataType = value
• Keyword Static replaces Dim
• Must be explicitly initialized in the
declaration
• Static variables
• Scope – local to the procedure
• Lifetime – duration of the program
• Necessary in event procedures with
variables that should be retained in
memory throughout program
execution
Counter
Variables
• A counter is a variable storing a
number that is incremented by a
constant value
• Useful for:
• Keeping track how many times a
button is clicked
• A guess is entered
• A password is typed
• A web site is visited
Counter
Variables
• Syntax:
• counter = counter + constant
• Counter is the numeric variable
that is updated
• Constant is the number that is
added to the current value of
the counter
• intNumTries = intNumTries + 1
• A counter should be declared as a
Static variable
The
Select…Case
Statement
• A decision structure that uses the
result of an expression to determine
which block of code to execute
• preferred to If…Then...ElseIf
• Takes the form:
Select expression
Case value
Statements
…
Case Else
Statements
End Select
The
Select…Case
Statement
Select Case intScore
Case 0, 10 'Score is 0 or 10
strMessage = "Nice try."
Case 20 To 25 'Score is 20, 21, 22, 23,
24, or 25
strMessage = "Great!"
Case Else 'Score other than 0, 10, 20,
21, 22, 23, 24, or 25
strMessage
End Select
‘Display message
Me.lblMessage.Text = strMessage
The
Select…Case
Statement
Start
Get User Input
Me.lblMessage.Text =
strMessage
Stop
Select
Case
intScore
Case 0, 10
strMessage = “Nice try”
Case 20 To 25
strMessage = "Great!"
Case Else
strMessage = "Invalid score."
Flowchart
The
Select…Case Is
Statement
• Compares the result of an expression
to a range of values
• Syntax:
SELECT CASE variableName
CASE IS < value
execute statement 1
CASE IS = value
execute statement 2
CASE IS > value
execute statement 3
END SELECT
The
Select…Case Is
Statement
Select Case intTestGrade
Case Is > 100
strMessage = "Invalid grade."
Case Is >= 93
strMessage = "A"
Case Is >= 85
strMessage = "B"
Case Is >= 78
strMessage = "C"
Case Is >= 69
strMessage = "D"
Case Is >= 0
strMessage = "F"
Case Else
strMessage = "Invalid grade."
End Select
Me.lblMessage.Text = strMessage
Review
Displaying a
Message Box
• A message box is a predefined dialog
box that displays a message for the
user
• Uses:
• Alert the user to invalid data
• A reminder of options required for
an application to continue
• MessageBox is a class that uses the
Show() method for displaying
More About Displaying a
Message Box
• Syntax:
• MessageBox.Show(message)
• Message is a variable
• A constant
• Or a string enclosed in quotation
marks
• MessageBox.Show(“Guess out of
range”)
More About Displaying a
Message Box
• Syntax:
• MessageBox.Show(message, title, button,
icon)
• Message is displayed in the dialog box
• Title is in the title bar
• Additional buttons can be added
• An icon can be displayed
• MessageBox.Show(“Guess out of range”,
“Guessing Game”,
MessageBoxButtons.RetryCancel,
MessageBoxIcon.Error)
The CheckBox
Control
• Allows the user to select options
• One or more check boxes can be
selected
• CheckBoxes can be placed inside a
GroupBox object
• CheckBox object has the properties:
• Name
• Identifies the control object
• Has prefix chk
• Text
• Text displayed next to the box
• Checked
• Can be set to True or False to display the
check box with or without a check
The CheckBox
Control
• CheckBoxes can have click events
• If…Then statement can be used in a
program to determine if a check box is
selected or cleared.
• Example:
Line-
Continuation
Character
• Visual Basic.NET statements that are
long can be typed onto two or more
lines when the line-continuation
character is used.
• The underscore (_) is the line-
continuation character and MUST have
a space before it and nothing after it
and cannot occur within quotation
marks.
Line-
Continuation
Character
• Example:
If Not (Me.chkBed.Checked And
Me.chkLunch.Checked _
And Me.chkHomework.Checked _
And Me.chkTeeth.Checked) Then
MessageBox.Show("Did you forget
something?")
• Properly dividing a statement into two
or more lines can make code easier to
read, which is good programming style

More Related Content

What's hot

What's hot (15)

Icom4015 lecture3-f17
Icom4015 lecture3-f17Icom4015 lecture3-f17
Icom4015 lecture3-f17
 
Icom4015 lecture4-f17
Icom4015 lecture4-f17Icom4015 lecture4-f17
Icom4015 lecture4-f17
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
 
Icom4015 lecture13-f16
Icom4015 lecture13-f16Icom4015 lecture13-f16
Icom4015 lecture13-f16
 
Icom4015 lecture8-f16
Icom4015 lecture8-f16Icom4015 lecture8-f16
Icom4015 lecture8-f16
 
Icom4015 lecture3-f16
Icom4015 lecture3-f16Icom4015 lecture3-f16
Icom4015 lecture3-f16
 
Cis 115 Extraordinary Success/newtonhelp.com
Cis 115 Extraordinary Success/newtonhelp.com  Cis 115 Extraordinary Success/newtonhelp.com
Cis 115 Extraordinary Success/newtonhelp.com
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
 
Advanced Programming Lecture 5 Fall 2016
Advanced Programming Lecture 5 Fall 2016Advanced Programming Lecture 5 Fall 2016
Advanced Programming Lecture 5 Fall 2016
 
CIIC 4010 Chapter 1 f17
CIIC 4010 Chapter 1 f17CIIC 4010 Chapter 1 f17
CIIC 4010 Chapter 1 f17
 
CiIC4010-chapter-2-f17
CiIC4010-chapter-2-f17CiIC4010-chapter-2-f17
CiIC4010-chapter-2-f17
 
Icom4015 lecture15-f16
Icom4015 lecture15-f16Icom4015 lecture15-f16
Icom4015 lecture15-f16
 
Intake 37 5
Intake 37 5Intake 37 5
Intake 37 5
 
Intake 37 6
Intake 37 6Intake 37 6
Intake 37 6
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selection
 

Similar to Module 7

Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptxZubairAli256321
 
Python programming workshop session 2
Python programming workshop session 2Python programming workshop session 2
Python programming workshop session 2Abdul Haseeb
 
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 LearningPrantikMaity6
 
Exception handling and function in python
Exception handling and function in pythonException handling and function in python
Exception handling and function in pythonTMARAGATHAM
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha BaliAkanksha Bali
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptxMattMarino13
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)ExcellenceAcadmy
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)ExcellenceAcadmy
 
An Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm ReviewAn Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm ReviewBlue Elephant Consulting
 
2 BytesC++ course_2014_c2_ flow of control
2 BytesC++ course_2014_c2_ flow of control 2 BytesC++ course_2014_c2_ flow of control
2 BytesC++ course_2014_c2_ flow of control kinan keshkeh
 
Python part two names and types
Python part two names and typesPython part two names and types
Python part two names and typesgrahamwell
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developersJim Roepcke
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 

Similar to Module 7 (20)

Python Basics
Python BasicsPython Basics
Python Basics
 
For Beginners - C#
For Beginners - C#For Beginners - C#
For Beginners - C#
 
Vba Class Level 1
Vba Class Level 1Vba Class Level 1
Vba Class Level 1
 
Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptx
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Python programming workshop session 2
Python programming workshop session 2Python programming workshop session 2
Python programming workshop session 2
 
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
 
Exception handling and function in python
Exception handling and function in pythonException handling and function in python
Exception handling and function in python
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
 
130706266060138191
130706266060138191130706266060138191
130706266060138191
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptx
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
 
An Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm ReviewAn Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm Review
 
2 BytesC++ course_2014_c2_ flow of control
2 BytesC++ course_2014_c2_ flow of control 2 BytesC++ course_2014_c2_ flow of control
2 BytesC++ course_2014_c2_ flow of control
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Python part two names and types
Python part two names and typesPython part two names and types
Python part two names and types
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developers
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 

More from obrienduke

VB Multiple Forms
VB Multiple FormsVB Multiple Forms
VB Multiple Formsobrienduke
 
VB Lines and Shapes
VB Lines and ShapesVB Lines and Shapes
VB Lines and Shapesobrienduke
 
Unit 4 bugs and debugging
Unit 4 bugs and debuggingUnit 4 bugs and debugging
Unit 4 bugs and debuggingobrienduke
 
Module 3 GUI Design
Module 3 GUI DesignModule 3 GUI Design
Module 3 GUI Designobrienduke
 
Arrays in java
Arrays in javaArrays in java
Arrays in javaobrienduke
 

More from obrienduke (9)

VB Multiple Forms
VB Multiple FormsVB Multiple Forms
VB Multiple Forms
 
VB Lines and Shapes
VB Lines and ShapesVB Lines and Shapes
VB Lines and Shapes
 
Graphics
GraphicsGraphics
Graphics
 
M14 overview
M14 overviewM14 overview
M14 overview
 
Mod 12
Mod 12Mod 12
Mod 12
 
Unit 4 bugs and debugging
Unit 4 bugs and debuggingUnit 4 bugs and debugging
Unit 4 bugs and debugging
 
Module 3 GUI Design
Module 3 GUI DesignModule 3 GUI Design
Module 3 GUI Design
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Nested loops
Nested loopsNested loops
Nested loops
 

Recently uploaded

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Recently uploaded (20)

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

Module 7

  • 1. Module 7 Created by S. O’Brien-Duke
  • 2. Logical Operators • Boolean Expressions • Evaluates to True or False • Can be formed using the logical operator And and Or • And • Expression evaluates to True only when both expressions (conditions) are True • If intGrade > 0 And intGrade < 100 Then Me.lblDisplay.Text = “Valid grade.”
  • 3. Logical Operators And Expression 1 intGrade > 0 Expression 2 intGrade < 100 Result Valid grade. True True True True False False False True False False False False
  • 4. Logical Operators • Or • If either expression (condition) is true, then the entire expression is True. • If intGuess < 1 Or IntGuess> 50 Then Me.lblMessage.Text = “Invalid number”.
  • 5. Logical Operators Or Expression 1 intGuess < 1 Expression 2 IntGuess> 50 Result Invalid number True True True True False False False True False False False False
  • 6. Logical Operators • Not • Is True only when the expression it is used with is False • Example: • strItem = “Pen” • If Not strItem = “Pen” Then Me.lblMessage.Text = “No discount”. • Would evaluate to False since strItem does equal “Pen”
  • 7. Logical Operators Not Expression strItem = “Pen” Result No discount True False False True
  • 8. Generating Random Numbers • Random numbers are needed for games, screen savers, and many other types of applications. • VB.NET has a built in Rnd() function that generates random numbers. • Using Rnd() alone generates number greater than or equal to zero (0) and less than one (1) • What if a random number between 0 and 10 is needed?
  • 9. Generating Random Numbers • A range can be specified using this formula • (HighNumber – LowNumber + 1) * Rnd() + LowNumber • Example: • We need a random number between 10 and 30 • ((30-10+1 ) * Rnd() + 10) • 21 * Rnd() + 10 • Using this formula we will have a decimal number…Why?
  • 10. Generating Random Numbers • Rnd() generates number greater than or equal to zero (0) and less than one (1) • Rnd() always generates a decimal • To generate an integer, the Int() function can be used • Int(21 * Rnd()) + 10 • The decimal potion of the calculation is truncated • Randomize() • Initializes the Rnd() function • Randomize() statement is added to the event procedure before the Rnd() function is used
  • 11. Static Variables • Variables have scope • Local scope – declared in a procedure • Called a local variable • Global scope – declared outside of the procedure • Called a global variable • Variables also have a lifetime • Local variable lifetime – duration of the procedure • Global variable lifetime – duration of the program
  • 12. Static Variables • Lifetime of a local variable can be extended by using a Static declaration statement • Static variableName as dataType = value • Keyword Static replaces Dim • Must be explicitly initialized in the declaration • Static variables • Scope – local to the procedure • Lifetime – duration of the program • Necessary in event procedures with variables that should be retained in memory throughout program execution
  • 13. Counter Variables • A counter is a variable storing a number that is incremented by a constant value • Useful for: • Keeping track how many times a button is clicked • A guess is entered • A password is typed • A web site is visited
  • 14. Counter Variables • Syntax: • counter = counter + constant • Counter is the numeric variable that is updated • Constant is the number that is added to the current value of the counter • intNumTries = intNumTries + 1 • A counter should be declared as a Static variable
  • 15. The Select…Case Statement • A decision structure that uses the result of an expression to determine which block of code to execute • preferred to If…Then...ElseIf • Takes the form: Select expression Case value Statements … Case Else Statements End Select
  • 16. The Select…Case Statement Select Case intScore Case 0, 10 'Score is 0 or 10 strMessage = "Nice try." Case 20 To 25 'Score is 20, 21, 22, 23, 24, or 25 strMessage = "Great!" Case Else 'Score other than 0, 10, 20, 21, 22, 23, 24, or 25 strMessage End Select ‘Display message Me.lblMessage.Text = strMessage
  • 17. The Select…Case Statement Start Get User Input Me.lblMessage.Text = strMessage Stop Select Case intScore Case 0, 10 strMessage = “Nice try” Case 20 To 25 strMessage = "Great!" Case Else strMessage = "Invalid score." Flowchart
  • 18. The Select…Case Is Statement • Compares the result of an expression to a range of values • Syntax: SELECT CASE variableName CASE IS < value execute statement 1 CASE IS = value execute statement 2 CASE IS > value execute statement 3 END SELECT
  • 19. The Select…Case Is Statement Select Case intTestGrade Case Is > 100 strMessage = "Invalid grade." Case Is >= 93 strMessage = "A" Case Is >= 85 strMessage = "B" Case Is >= 78 strMessage = "C" Case Is >= 69 strMessage = "D" Case Is >= 0 strMessage = "F" Case Else strMessage = "Invalid grade." End Select Me.lblMessage.Text = strMessage
  • 20. Review Displaying a Message Box • A message box is a predefined dialog box that displays a message for the user • Uses: • Alert the user to invalid data • A reminder of options required for an application to continue • MessageBox is a class that uses the Show() method for displaying
  • 21. More About Displaying a Message Box • Syntax: • MessageBox.Show(message) • Message is a variable • A constant • Or a string enclosed in quotation marks • MessageBox.Show(“Guess out of range”)
  • 22. More About Displaying a Message Box • Syntax: • MessageBox.Show(message, title, button, icon) • Message is displayed in the dialog box • Title is in the title bar • Additional buttons can be added • An icon can be displayed • MessageBox.Show(“Guess out of range”, “Guessing Game”, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error)
  • 23. The CheckBox Control • Allows the user to select options • One or more check boxes can be selected • CheckBoxes can be placed inside a GroupBox object • CheckBox object has the properties: • Name • Identifies the control object • Has prefix chk • Text • Text displayed next to the box • Checked • Can be set to True or False to display the check box with or without a check
  • 24. The CheckBox Control • CheckBoxes can have click events • If…Then statement can be used in a program to determine if a check box is selected or cleared. • Example:
  • 25. Line- Continuation Character • Visual Basic.NET statements that are long can be typed onto two or more lines when the line-continuation character is used. • The underscore (_) is the line- continuation character and MUST have a space before it and nothing after it and cannot occur within quotation marks.
  • 26. Line- Continuation Character • Example: If Not (Me.chkBed.Checked And Me.chkLunch.Checked _ And Me.chkHomework.Checked _ And Me.chkTeeth.Checked) Then MessageBox.Show("Did you forget something?") • Properly dividing a statement into two or more lines can make code easier to read, which is good programming style