Until now we have only been using sequential flow. Visual Basic Data Types. Relational Operators ... between alternative suggestions by testing the value of key ... – PowerPoint PPT presentation
2 VB Course Plan Week 1 Introduction to Visual Basic Week 2 Decisions and Repetitions Week 3 Functions and Subroutines Week 4 Arrays and other applications 3 What we will cover today!
Visual Basic data types
Relational and logical operators in Visual Basic
How Visual Basic assigns control in a program
4 At the end of todays lecture .
You should be able to
assign values/information to different variable types
code arithmetic operations
Control the execution flow within a Visual Basic program
5 Data Types
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Numbers
Dim interestRate As Single
Dim range As Double
Dim age As Integer
,-,/,,
Strings
Dim phrase As String
Dim variable name As variable type 6 Relational Operators
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
A condition is an expression involving relational operators that is either true or false
7 Class Activity
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Determine whether the following are true or false
1 lt 1
car lt cat
1lt1
If a4 and b3 (ab)lt2a
8 Logical Operators
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
More complex situations are normally required ie (2ltn) And (nlt5)
cond1 And cond2
cond1 Or cond2
Not cond1
9 Class Activity
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Determine whether the following are true or false if n has a value of 4 and the string variable answ has a value Y
(2ltn) And (nlt6)
(2ltn) Or (n6)
Not (Nlt6)
(answY) And (answ y)
10 Control Structures
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Control structures control the flow of execution in a program or function.
Visual Basic control structures allow you to combine individual instructions into a single logical unit with one entry point and one exit point.
Instructions are organised into three kinds of control structures to control execution flow sequence, selection and repetition.
11 Sequence
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Until now we have only been using sequential flow
12 Selection
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
A selection control structure chooses which alternative to execute.
A program chooses between alternative suggestions by testing the value of key variables.
A condition is an expression that is either false or true. It establishes a criterion for either executing or skipping a group of statements.
13 If Blocks
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
An If Block allows a program to decide on a course of action based on whether a certain condition is true or false
The if statement is the primary selection control structure.
If condition Then action 1 Else action 2 End If 14 If Blocks
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
15 Example If Blocks
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Task Write a program to find the larger of two numbers input by the user. 16 Example If Blocks
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
What is the problem asking us to do?
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and document 17 Class Activity If Blocks
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Problem Inputs
Problem Outputs
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and document 18 Class Activity If Blocks
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Get the data
Perform the computations
Display the results
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and document 19 Class Activity If Blocks
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 20 Class Activity If Blocks
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 21 Class Activity If Blocks
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Test the program for all cases. What test cases would you use? Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 22 Class Activity If Blocks
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Include some documentation in the code you have just written Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 23 Nested If Blocks
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
24 If Blocks and Logical Operators
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
25 Repetition
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
A repetition structure allows the programmer to specify that an action is to be repeated until some terminating condition occurs.
The repetition of steps in a program is called a loop.
26 Repetition
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
No No loop required Any steps repeated Yes No Know in advance how many times to repeat Do loops Yes Use a for loop 27 Do Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Repeats a sequence of statements either as long as or until a certain condition is true
Do while condition statements Loop Do statements Loop Until Condition 28 Example
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Task Write a program that displays the numbers 1 through 10. 29 Class Activity Do Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
What is the problem asking us to do?
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and document 30 Class Activity Do Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Problem Inputs
Problem Outputs
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and document 31 Class Activity Do Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Get the data
Perform the computations
Display the results
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and document 32 Class Activity Do Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 33 Class Activity Do Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 34 Class Activity Do Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Test the program for all cases. What test cases would you use? Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 35 Class Activity Do Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Include some documentation in the code you have just written Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 36 For Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
When we know exactly how many times a loop should be executed as opposed to until a condition is met as in the do loop
For i m to n Step s statements Next m 37 Example For Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Task Suppose the population of a city is 300,000 in the year 1998 and is growing at the rate of 3 per year. Display a table showing the population of each year until 2002 38 Class Activity For Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
What is the problem asking us to do?
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and document 39 Class Activity For Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Problem Inputs
Problem Outputs
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and document 40 Class Activity For Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Get the data
Perform the computations
Display the results
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and document 41 Class Activity For Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 42 Class Activity For Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 43 Class Activity For Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Test the program for all cases. What test cases would you use? Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 44 Class Activity For Loops
Visual Basic Data Types
Relational Operators
Logical Operators
Control Structures
Sequence
Selection
Repetition
Include some documentation in the code you have just written Specify the problem requirements Analyse the problem Design the algorithm to solve the problem Choose the interface Implement the algorithm Test and verify the completed program Maintain and documentation 45 Class Activity
Task
Write a program that requests the user to enter a number n, from 1 to 30 and one of the letters S or P. Then calculate the sum of product of the numbers from 1 to n depending upon whether S or P was selected.
46 VB Course Plan Week 1 Introduction to Visual Basic Week 2 Decisions and Repetitions Week 3 Functions and Subroutines Week 4 Arrays and other applications
PowerShow.com is a leading presentation sharing website. It has millions of presentations already uploaded and available with 1,000s more being uploaded by its users every day. Whatever your area of interest, here you’ll be able to find and view presentations you’ll love and possibly download. And, best of all, it is completely free and easy to use.
You might even have a presentation you’d like to share with others. If so, just upload it to PowerShow.com. We’ll convert it to an HTML5 slideshow that includes all the media types you’ve already added: audio, video, music, pictures, animations and transition effects. Then you can share it with your target audience as well as PowerShow.com’s millions of monthly visitors. And, again, it’s all free.
About the Developers
PowerShow.com is brought to you by CrystalGraphics, the award-winning developer and market-leading publisher of rich-media enhancement products for presentations. Our product offerings include millions of PowerPoint templates, diagrams, animated 3D characters and more.