Decision Structures. Start. Do I have a test in morning? Study for test. Watch TV tonight. Stop

Size: px
Start display at page:

Download "Decision Structures. Start. Do I have a test in morning? Study for test. Watch TV tonight. Stop"

Transcription

1 Decision Structures In the programs created thus far, Visual Basic reads and processes each of the procedure instructions in turn, one after the other. This is known as sequential processing or as the sequence structure. There are however two other programming structures known as decision structures and repetition structures. Many applications use decision (or selection) structures to control which program instructions are processed. Decision structures enable a program to make decisions, or comparisons, and then select one of two program paths based on the result. This structure can be thought of as a fork in a road and can be represented visually using a flowchart. In a typical day, you probably make hundreds of decisions. For example if you have a test tomorrow morning, then you should study tonight, if not, you can watch the late night showing of Greys Anatomy on TV. This could be represented using a flowchart. Start Do I have a test in morning? Y Study for test N Watch TV tonight Stop In the above flowchart, the diamond shape represents the decision structure. Inside the diamond is a question or condition with a yes/no answer. The decision structure has one flow-line leading into it, and two flow-lines leading out of it. The out-flowing lines are marked with Y & N (for Yes/No) or T & F (for True/False) to clearly indicate the true path from the false path. Flowcharts can be used to show the steps that must be completed in order to accomplish a task. To translate a flowchart into VB code, simply start at the top and write the code for each symbol as you follow the flow-lines down the flowchart. Some symbols may require several lines of code, while the start symbol requires no coding.

2 The IF Then Statement The If Then statement executes a set of statements when a condition is true. Syntax: If condition Then statements executed when condition is true For example in the following If Then statement intcredits >= 20 is the condition and there is one statement that will be executed when the condition is true. If intcredits >= 20 Then lblmessage.text= Congratulations, you can graduate this year! Care must be taken when writing the condition of an If Then statement as it must be written as a Boolean expression that evaluates to true or false. In the above condition, the relational operator >= is used to determine the value of the variable intcredits. If the value is greater than or equal to 20, then the Text property of lblmessage will be changed to display the message congratulations, you can graduate this year!. If the value is less than 2, the statement is not executed as the condition is not true. Program flow continues to the code directly after the Relational Operators Operator Meaning = equal to < less than > greater than >= greater than OR equal to <= less than OR equal to <> not equal to

3 Lab# 6 Decisions You will create a grading application that enables the user to enter a test mark. If the mark entered is greater than 90, the message Good job A+ should be displayed. Open a new Project and create the form at the right. Name the project Grading. Make the following changes to the controls: Form1 MenuStrip Label 1 Label 2 Name - frmgrading Text Grading Form1.vb renamed MainForm Name - lblenterprompt Text Enter a Numeric Grade File Name -mnufile Process Name mnufileprocess Clear Name mnufileclear TextBox Button Name - lblmessage Text Grade Information Name - txtnumericgrade Name - cmdprocess Text Process Exit Help About Name mnufileexit Name mnuhelp Name -mnuhelpabout

4 In this program, we are going to code for five events, all clicks of the mouse on the menu objects or the command button. When the Exit menu is clicked, the program will close. We have seen this code in the last lab. When the Clear menu is clicked, the value in the textbox and the value in the Message label will be cleared (Message caption will change to reflect the Grade Information message). When the Process button is clicked or when the Process menu is clicked, the program will determine if the entered value is greater than 90. If it is, the message label will change. Planning: For this program we will need the following: No formulas needed Variables: grade needs to be a number, decimals should be allowed The scope of these variables needs only to be used within the form class, thus, they should be declared after Public Class and before any of the subroutines using Private.

5 The flowchart for the Process procedure looks like this: Start Get numeric grade from user Convert value to a number Is value >= 90? N Y Display message Good Work A+ Stop

6 Pseudo-code: Declare Variable Grade (Use Option Explicit On and Option Infer Off) mnufileexit _Click Exit program mnufileclear_click clear contents of textbox (set to empty strings) reset label for message to Grade Information cmdprocess_click AND mnufileprocess_click get user input from text box and put them into variable using Val to convert to Numeric data If variable > 90 then display the message Good Job A+ in the label mnuhelpabout_click Display MessageBox with program details. Code: 'Grading Application 'purpose: to introduce Decision Structures to students. 'Program will request a grade from the user and if the 'value is greater than 90, a message will display "Good job A+" 'of a sqaure that has that length measurement. 'Written by Computer Teacher, One day 'Modified by you, today Option Explicit On Option Infer Off

7 Public Class frmgrading 'Declare variables Private snggrade As Single Private Sub cmdprocess_click(byval sender As System.Object, ByVal e As System.EventArgs) Handles cmdprocess.click snggrade = Val(txtNumericGrade.Text If snggrade > 90 Then lblmessage.text = "Good Job A+" 'converts textbox value to number 'decision structure 'repeat of code from Command Button Private Sub mnufileprocess_click(byval sender As Object, ByVal e As System.EventArgs) Handles mnufileprocess.click snggrade = Val(txtNumericGrade.Text) If snggrade > 90 Then lblmessage.text = "Good Job A+" converts textbox value to number 'decision structure 'Exit program Private Sub mnufileexit_click(byval sender As Object, ByVal e As System.EventArgs) Handles mnufileexit.click Me.Close() 'Displays information about the program Private Sub mnuhelpabout_click(byval sender As Object, ByVal e As System.EventArgs) Handles mnuhelpabout.click MessageBox.Show("Letter Grading messenger", "Grading 2.0") 'clear text box and reset message Private Sub mnufileclear_click(byval sender As Object, ByVal e As System.EventArgs) Handles mnufileclear.click lblmessage.text = "Grade Information" txtnumericgrade.text = " " End Class 'empty string Save All and test your program. If you enter a grade of 90 or below, no action is taken as there is no allowance for that in the code.

8 The IF Then Statement The If Then statement executes one set of statements when a condition is true and another set of statements if the condition is not true. Syntax: The If Then statement takes the form: If condition Then statements executed when condition IS true statements executed when condition IS NOT true Only ONE of the above statements can be executed, depending on if the condition evaluates as true or false. In the following example, if the condition radadd.checked=true evaluates as true (meaning the radio button radadd is checked), then program flow continues to the statements immediately below the condition. The variable sngsum is therefore calculated by adding the contents of the two textboxes Mark1 and Mark2. The text property of the label control lblanswer would then be updated as shown. Program flow would then skip ahead to the end of the statement. If the condition evaluates as false (meaning the radio button radadd is NOT checked) then program flow skips the statements immediately following the condition, and instead jumps ahead and executes the statements following the statement. In this case the variable sngsum would be assigned the value zero. Program flow then continues. If radadd.checked = True Then sngsum = Val(txtMark1.text) + Val(txtMark2.text) lblanswer.text = The sum of the marks is & sngsum sngsum = 0

9 Lab# 6 continued We will modify the previous grade application so that in addition to displaying Good job A+ for marks greater than 90, the message Good work, keep practicing! is displayed for marks of 90 or less. Our form will not need to change, nor will our variable. The flowchart would need to be changed to reflect another message after the decision: Is value >= 90? N Y Display message Good Work A+ Display message Not bad keep going Stop The pseudocode changes are only to the Process procedures: cmdprocess_click AND mnufileprocess_click get user input from text box and put them into variable using Val to convert to Numeric data If variable > 90 then display the message Good Job A+ in the label Display the message Not bad keep going

10 Code (note that there are only two lines added to each procedure): Private Sub cmdprocess_click(byval sender As System.Object, ByVal e As System.EventArgs) Handles cmdprocess.click snggrade = Val(txtNumericGrade.Text) 'converts text box value to numeric value If snggrade > 90 Then 'decision structure lblmessage.text = "Good Job A+" lblmessage.text = "Not bad...keep going" 'repeat of code from Command Button Private Sub mnufileprocess_click(byval sender As Object, ByVal e As System.EventArgs) Handles mnufileprocess.click snggrade = Val(txtNumericGrade.Text) 'converts text box value to numeric value If snggrade > 90 Then 'decision structure lblmessage.text = "Good Job A+" lblmessage.text = "Not bad...keep going"

11 Logical Operators Logical operators (AND, OR, NOT) can also be used to combine several conditions into one compound condition. The chart below shows the three most commonly used operators and their meaning. Logical Operator AND OR NOT Meaning ALL conditions connected by the AND operator must be true for the compound operator to evaluate as true. Only ONE of the conditions connected by the OR operator needs to be true for the compound operator to evaluate as true. REVERSES the value of the condition. True becomes false, false becomes true. Truth Table for AND operator Value of Condition 1 Value of Condition 2 Value of Compound condition (condition 1 AND condition 2) True True True True False False False True False False False False Truth Table for OR operator Value of Condition 1 Value of Condition 2 Value of Compound condition (condition 1 OR condition 2) True True True True False True False True True False False False Truth Table for NOT operator Value of Condition True False Value of NOT Condition False True

12 Truth Tables explained The truth tables show the possible combinations in which the separate conditions that make up a compound condition can evaluated using logical operators, along with their combined result. AND operator Notice that when the AND logical operator is used to combine the two conditions, condition 1 and condition 2, then the resulting compound condition is True ONLY when BOTH conditions are True. If either condition is False, or if both are False, then the compound condition evaluates as False. When Visual Basic evaluates a compound condition that uses an AND operator, if the first condition is False, then the second condition is not even evaluated. Also, if either one of the conditions is False, the resulting compound condition must also be False. OR operator When the OR logical operator is used to combine the two conditions, condition 1 and condition 2, then the resulting compound condition is False only when BOTH conditions are False. If either condition is True, or if both are TRUE, then the compound condition evaluates as TRUE. NOT operator Reverses the Truth condition of the operator. Use of the NOT operator is best avoided if possible as it can be confusing! Just like expressions that contain relational operators, expressions containing logical operators always result in either a True or False answer. In the case of compound expressions, any mathematical operators are evaluated first, relational operators are operated next, and logical operators are evaluated last. For example in the following compound expression 8 > 4 AND 10 < 2 * 6 uses the AND logical operator and evaluates as True. 2*6 is evaluated first resulting In 8 > 4 AND 10 < 12 8 > 4 is evaluated next resulting In True AND 10 <12 10 < 12 is evaluated next resulting In True AND True Exercise True AND True is evaluated last resulting In True Calculate and determine if the following compound expressions evaluate as True or false > 0 AND 12 < 10 * / 3 > 4 AND 12 < 7 * ^2 > 10 AND 2 * < < 2 * 7 OR 12 > 10 * * 2 > 3* OR 12 / 6 2 > 10 * SQR(9) 6 * 7-2

13 Nested If Then Statements If Then statements can each contain another If Then statement, and is then said to be nested. Syntax: Nested If Then statements take the form: If condition 1 Then statements executed when condition1 is true If condition 2 Then statements executed when condition2 is true If condition 3 Then statements executed when condition 3 is true statements It is good programming style to indent nested If Then statements as shown. The last statement is optional. In the following example, if the radio button radcube is checked then the variable sngvolume is calculated using the formula for the volume of a cube and is then displayed. if the radio button radsphere is checked instead, then the value of sngvolume is calculated using the formula for the volume of a sphere. If radcube.checked=true Then sngvolume = length * width * height lblmessage.text = Volume of cube is & sngvolume If radsphere.checked=true Then sngvolume = 4/3 * 3.14 * radius^3 lblmessage.text = Volume of cube is & sngvolume sngvolume =0 lblmessage.visible=false

14 The IF Then If Statement The If Then If statement is generally used to decide among 3 or more actions. Syntax: The If Then If statement takes the form: If condition 1 Then statements executed when condition 1 is true If condition 2 Then statements executed when condition 2 is true If condition3 Then statements executed when condition 3 is true statement There can be multiple If statements as shown above. The last statement is optional. Decision structures with several branches can be difficult to understand so should include inline comments to help explain the logic. This is especially true of the last branch of a decision structure which does not always include an explicit instruction! A single If Then If statement is generally easier to understand and considered better programming style than nested If Then statements.

15 Lab# 6 Continued Modify the grades lab to reflect the following: If mark 80 and above, display Excellent, grade A If mark 70 and above, but less than80, display Well done, grade B If mark 60 and above, but less than 70, display Pass, grade C If mark < 60, display Try studying more Our form will not need to change, nor will our variable. The flowchart would need to be changed to reflect another message after the decision: Is value >=80? N Y Display message Excellent, Grade A Is value >=70 & <80? N Y Display message Well done, Grade B Is value >=60 & <70? N Y Display message Pass, Grade C Display message Try studying more Stop

16 Code Private Sub cmdprocess_click(byval sender As System.Object, ByVal e As System.EventArgs) Handles cmdprocess.click snggrade = Val(txtNumericGrade.Text) 'converts text box value to numeric value If snggrade >= 80 Then 'decision structure lblmessage.text = "Excellent, Grade A" If snggrade >= 70 And snggrade < 80 Then lblmessage.text = "Well done, Grade B" If snggrade >= 60 And snggrade < 70 Then lblmessage.text = "Pass, Grade C" lblmessage.text = "Try studying more" Don t forget to place the same code in the mnufile Process_Click procedure. Save all and test your program with several different data to ensure that it functions properly. The Select Case Statement The Select Case statement is a decision structure that is useful used as an alternative to nested If Then statements as the code is generally easier to read. The select case structure uses the result of a condition to determine which statements to execute. Syntax: The Select Case statement takes the form. Select Case expression Case value 1 statement executed if value 1 true Case value 2 statement executed if value 2 true Case statement executed if value 1 AND value 2 NOT true End Select

17 For example the Select Case statement below assigns a value to the variable curcost, depending on the value of the variable intgroupsize. If intgroupsize=1 then curcost=50. If intgroupsize=2 then curcost=75. Select Case intgroupsize Case 1 curcost=50 Case 2 curcost=75 Case 3 curcost=100 End Select The Select Case Is Statement The Select Case Is statement compares the result of an expression to a range of values when a relational operator is part of the value. Select Case intspeed Case Is < 74 lblmessage.text = "Not Hurricaine strength" Case Is < 95 lblmessage.text = "Category 1 Hurricaine" Case Is < 110 lblmessage.text = "Category 2 Hurricaine" Case Is < 130 lblmessage.text = "Category 3 Hurricaine" End Select For example the Select Case Is statement below uses a relational operator to compare the value of the variable intspeed to the values shown. The lblmessage.text will therefore be changed depending on the windspeed represented by the variable intspeed.

18 Random Numbers Random Numbers are required by many types of applications, such as games, simulators, and screen savers. The RND ( ) function generates a random number greater or equal to 0 and less than 1. Remember a function is a procedure that performs a task and returns a value. IE. lblrandom.text = Rnd( ) Larger Range To generate random numbers in a greater range, multiply Rnd by the upper limit of the range. IE. lblrandom.text = Rnd( ) * 10 Changing the lower limit If you would like to use a lower limit other than zero, use the following syntax: (High_Number - Low_Number +1) * Rnd() + Low_Number High_Number - the maximum value desired. Low_Number - the minimum value desired. Example lblrandom.text = 16 * Rnd ( )+ 20 Would give a range of 20 to 45. To figure this out use the formula of high_number low_number +1 = number before Rnd or (X ) = 16 INT The INT() function returns an integer portion of a number (without rounding). Combining INT and RND will produce random integers. IE. lblrandom.text = Int ( 16 * Rnd( ) + 20)

19 Randomize Programs using random numbers need the Randomize ( ) statement in order for different numbers to be generated each run of the program. The Randomize statement should only be executed once in a program and be placed before any call of the Rnd () function, thus placing it in the form_load procedure is the best place for it. IE. Private Sub Form _ Load ( ) Randomize () initializes random number generator

VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals

VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals VARIABLES WHAT IS A VARIABLE? A variable is a storage location in the computer s memory, used for holding information while the program is running. The information that is stored in a variable may change,

More information

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017 Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

More information

Repetition Structures

Repetition Structures Repetition Structures There are three main structures used in programming: sequential, decision and repetition structures. Sequential structures follow one line of code after another. Decision structures

More information

LECTURE 5 Control Structures Part 2

LECTURE 5 Control Structures Part 2 LECTURE 5 Control Structures Part 2 REPETITION STATEMENTS Repetition statements are called loops, and are used to repeat the same code multiple times in succession. The number of repetitions is based on

More information

Making Decisions and Working with Strings

Making Decisions and Working with Strings GADDIS_CH04 12/16/08 6:47 PM Page 193 CHAPTER 4 Making Decisions and Working with Strings TOPICS 4.1 The Decision Structure 4.2 The If...Then Statement 4.3 The If...Then...Else Statement 4.4 The If...Then...ElseIf

More information

CHAPTER 2 PROBLEM SOLVING TECHNIQUES. Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042

CHAPTER 2 PROBLEM SOLVING TECHNIQUES. Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042 CHAPTER 2 PROBLEM SOLVING TECHNIQUES Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042 Software Engineering vs Problem Solving Software Engineering - A branch of Computer Science & provides

More information

Visual Basic 2008 The programming part

Visual Basic 2008 The programming part Visual Basic 2008 The programming part Code Computer applications are built by giving instructions to the computer. In programming, the instructions are called statements, and all of the statements that

More information

VB FUNCTIONS AND OPERATORS

VB FUNCTIONS AND OPERATORS VB FUNCTIONS AND OPERATORS In der to compute inputs from users and generate results, we need to use various mathematical operats. In Visual Basic, other than the addition (+) and subtraction (-), the symbols

More information

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017 Loops! Loops! Loops! Lecture 5 COP 3014 Fall 2017 September 25, 2017 Repetition Statements Repetition statements are called loops, and are used to repeat the same code mulitple times in succession. The

More information

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

More information

Microsoft Visual Basic 2005: Reloaded

Microsoft Visual Basic 2005: Reloaded Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program Objectives After studying this chapter, you should be able to: Include the selection structure in pseudocode

More information

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

Flow of Control. Flow of control The order in which statements are executed. Transfer of control 1 Programming in C Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed Programming in C 1 Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

To enter the number in decimals Label 1 To show total. Text:...

To enter the number in decimals Label 1 To show total. Text:... Visual Basic tutorial - currency converter We will use visual studio to create a currency converter where we can convert a UK currency pound to other currencies. This is the interface for the application.

More information

In this tutorial we will create a simple calculator to Add/Subtract/Multiply and Divide two numbers and show a simple message box result.

In this tutorial we will create a simple calculator to Add/Subtract/Multiply and Divide two numbers and show a simple message box result. Simple Calculator In this tutorial we will create a simple calculator to Add/Subtract/Multiply and Divide two numbers and show a simple message box result. Let s get started First create a new Visual Basic

More information

Individual research task. You should all have completed the research task set last week. Please make sure you hand it in today.

Individual research task. You should all have completed the research task set last week. Please make sure you hand it in today. Lecture 6 Individual research task. You should all have completed the research task set last week. Please make sure you hand it in today. Previously Decision structures with flowcharts Boolean logic UML

More information

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode STUDENT OUTLINE Lesson 8: Structured Programming, Control Structures, if- Statements, Pseudocode INTRODUCTION: This lesson is the first of four covering the standard control structures of a high-level

More information

NOTES: Variables & Constants (module 10)

NOTES: Variables & Constants (module 10) Computer Science 110 NAME: NOTES: Variables & Constants (module 10) Introduction to Variables A variable is like a container. Like any other container, its purpose is to temporarily hold or store something.

More information

Chapter 4 The If Then Statement

Chapter 4 The If Then Statement The If Then Statement Conditional control structure, also called a decision structure Executes a set of statements when a condition is true The condition is a Boolean expression For example, the statement

More information

HOUR 4 Understanding Events

HOUR 4 Understanding Events HOUR 4 Understanding Events It s fairly easy to produce an attractive interface for an application using Visual Basic.NET s integrated design tools. You can create beautiful forms that have buttons to

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

Programming for Engineers Iteration

Programming for Engineers Iteration Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers

More information

MIS 216 SPRING 2018 PROJECT 4

MIS 216 SPRING 2018 PROJECT 4 MIS 216 SPRING 2018 PROJECT 4 Subs / Functions Arrays / Classes 1. Start a new project a. Create a folder on your desktop name it yourinitialsproject3 as in tnjproject3. b. FILE NEW PROJECT c. Change the

More information

Flow Charts. Visual Depiction of Logic Flow

Flow Charts. Visual Depiction of Logic Flow Flow Charts Visual Depiction of Logic Flow Flow Charts Describe a sequence of events using pictures Often associated with computer programs, but are quite common in other fields General way to depict a

More information

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS Objectives By the end of this section you should be able to:

More information

5. Control Statements

5. Control Statements 5. Control Statements This section of the course will introduce you to the major control statements in C++. These control statements are used to specify the branching in an algorithm/recipe. Control statements

More information

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Introduction to: Computers & Programming: Review prior to 1 st Midterm Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in

More information

Programming with Visual Studio Higher (v. 2013)

Programming with Visual Studio Higher (v. 2013) Programming with Visual Studio Higher (v. 2013) Contents/Requirements Checklist Multiple selection: using ifs & case While Loops Using arrays Filling arrays Displaying array contents Types of variables:

More information

Visual basic tutorial problems, developed by Dr. Clement,

Visual basic tutorial problems, developed by Dr. Clement, EXCEL Visual Basic Tutorial Problems (Version January 20, 2009) Dr. Prabhakar Clement Arthur H. Feagin Distinguished Chair Professor Department of Civil Engineering, Auburn University Home page: http://www.eng.auburn.edu/users/clemept/

More information

Tutorial 03 understanding controls : buttons, text boxes

Tutorial 03 understanding controls : buttons, text boxes Learning VB.Net Tutorial 03 understanding controls : buttons, text boxes Hello everyone welcome to vb.net tutorials. These are going to be very basic tutorials about using the language to create simple

More information

CS 199 Computer Programming. Spring 2018 Lecture 5 Control Statements

CS 199 Computer Programming. Spring 2018 Lecture 5 Control Statements CS 199 Computer Programming Spring 2018 Lecture 5 Control Statements Control Structures 3 control structures Sequence structure Programs executed sequentially by default Branch structure Unconditional

More information

Engineering program development. Edited by Péter Vass

Engineering program development. Edited by Péter Vass Engineering program development Edited by Péter Vass Introduction Question: Why engineering program development may be useful for a PhD student in Earth Sciences? Counter-argument: In these days a wide

More information

Lesson 6A Loops. By John B. Owen All rights reserved 2011, revised 2014

Lesson 6A Loops. By John B. Owen All rights reserved 2011, revised 2014 Lesson 6A Loops By John B. Owen All rights reserved 2011, revised 2014 Topic List Objectives Loop structure 4 parts Three loop styles Example of a while loop Example of a do while loop Comparison while

More information

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4. Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations

More information

CS110D: PROGRAMMING LANGUAGE I

CS110D: PROGRAMMING LANGUAGE I CS110D: PROGRAMMING LANGUAGE I Computer Science department Lecture 5&6: Loops Lecture Contents Why loops?? While loops for loops do while loops Nested control structures Motivation Suppose that you need

More information

Repetition CSC 121 Fall 2014 Howard Rosenthal

Repetition CSC 121 Fall 2014 Howard Rosenthal Repetition CSC 121 Fall 2014 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while

More information

5. Selection: If and Switch Controls

5. Selection: If and Switch Controls Computer Science I CS 135 5. Selection: If and Switch Controls René Doursat Department of Computer Science & Engineering University of Nevada, Reno Fall 2005 Computer Science I CS 135 0. Course Presentation

More information

Chapter 3 Structured Program Development

Chapter 3 Structured Program Development 1 Chapter 3 Structured Program Development Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 3 - Structured Program Development Outline 3.1 Introduction

More information

Functions and Procedures. Functions. Built In Functions. Built In Functions in VB FIT 100 FIT 100

Functions and Procedures. Functions. Built In Functions. Built In Functions in VB FIT 100 FIT 100 Functions Functions and Procedures Similarities: Little mini-programs that are named and include a series of code statements (instructions) to be executed when called. Differences: Functions have a specific

More information

Skill Area 306: Develop and Implement Computer Program

Skill Area 306: Develop and Implement Computer Program Add your company slogan Skill Area 306: Develop and Implement Computer Program Computer Programming (YPG) LOGO Skill Area 306.2: Produce Structured Program 306.2.1 Write Algorithm 306.2.2 Apply appropriate

More information

Example: Monte Carlo Simulation 1

Example: Monte Carlo Simulation 1 Example: Monte Carlo Simulation 1 Write a program which conducts a Monte Carlo simulation to estimate π. 1 See https://en.wikipedia.org/wiki/monte_carlo_method. Zheng-Liang Lu Java Programming 133 / 149

More information

Control Structures in Java if-else and switch

Control Structures in Java if-else and switch Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2017 January 23, 2017 Lecture 4CGS 3416 Spring 2017 Selection January 23, 2017 1 / 26 Control Flow Control flow refers to the specification

More information

FLOW CHART AND PSEUDO CODE

FLOW CHART AND PSEUDO CODE FLOW CHART AND PSEUDO CODE Flowchart A Flowchart is a pictorial representation of an algorithm. The First flowchart is made by John Von Newman in 1945. It is a symbolic diagram of operation sequence, dataflow,

More information

Programming Language 2 (PL2)

Programming Language 2 (PL2) Programming Language 2 (PL2) 337.1.1 - Explain rules for constructing various variable types of language 337.1.2 Identify the use of arithmetical and logical operators 337.1.3 Explain the rules of language

More information

Wyo VB Lecture Notes - Objects, Methods, & Properties

Wyo VB Lecture Notes - Objects, Methods, & Properties Wyo VB Lecture Notes - Objects, Methods, & Properties Objective #1: Use forms appropriately. A form is a basic building block of a Visual Basic project. Eventually, you'll be creating projects that consist

More information

Computers Programming Course 6. Iulian Năstac

Computers Programming Course 6. Iulian Năstac Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap

More information

Chapter 1: Problem Solving Skills Introduction to Programming GENG 200

Chapter 1: Problem Solving Skills Introduction to Programming GENG 200 Chapter 1: Problem Solving Skills Introduction to Programming GENG 200 Spring 2014, Prepared by Ali Abu Odeh 1 Table of Contents Fundamentals of Flowcharts 2 3 Flowchart with Conditions Flowchart with

More information

Introduction to C Programming

Introduction to C Programming 1 2 Introduction to C Programming 2.6 Decision Making: Equality and Relational Operators 2 Executable statements Perform actions (calculations, input/output of data) Perform decisions - May want to print

More information

Microsoft Visual Basic 2015: Reloaded

Microsoft Visual Basic 2015: Reloaded Microsoft Visual Basic 2015: Reloaded Sixth Edition Chapter Three Memory Locations and Calculations Objectives After studying this chapter, you should be able to: Declare variables and named constants

More information

Chapter 4: Making Decisions. Copyright 2012 Pearson Education, Inc. Sunday, September 7, 14

Chapter 4: Making Decisions. Copyright 2012 Pearson Education, Inc. Sunday, September 7, 14 Chapter 4: Making Decisions 4.1 Relational Operators Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >= Greater than or equal to

More information

Chapter 3. More Flow of Control. Copyright 2008 Pearson Addison-Wesley. All rights reserved.

Chapter 3. More Flow of Control. Copyright 2008 Pearson Addison-Wesley. All rights reserved. Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

More information

Chapter 4: Control structures. Repetition

Chapter 4: Control structures. Repetition Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition

More information

Chapter 4: Making Decisions

Chapter 4: Making Decisions Chapter 4: Making Decisions 4.1 Relational Operators Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >= Greater than or equal to

More information

BITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17)

BITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17) BITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17) 1 Learning Outcomes At the end of this lecture, you should be able to: 1. Explain the concept of selection control structure

More information

Computational Expression

Computational Expression Computational Expression Conditionals Janyl Jumadinova 10 October, 2018 Janyl Jumadinova Computational Expression 10 October, 2018 1 / 16 Computational Thinking: a problem solving process Decomposition

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 15 Branching : IF ELSE Statement We are looking

More information

Mr.Khaled Anwar ( )

Mr.Khaled Anwar ( ) The Rnd() function generates random numbers. Every time Rnd() is executed, it returns a different random fraction (greater than or equal to 0 and less than 1). If you end execution and run the program

More information

Loops / Repetition Statements

Loops / Repetition Statements Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for

More information

LOOPS. Repetition using the while statement

LOOPS. Repetition using the while statement 1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while

More information

Introduction to Programming

Introduction to Programming Introduction to Programming session 6 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Spring 2011 These slides are created using Deitel s slides Sharif University of Technology Outlines

More information

Chapter 4: Making Decisions

Chapter 4: Making Decisions Chapter 4: Making Decisions CSE 142 - Computer Programming I 1 4.1 Relational Operators Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >=

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Control Structures in Java if-else and switch

Control Structures in Java if-else and switch Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2016 February 2, 2016 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions

More information

A Complete Tutorial for Beginners LIEW VOON KIONG

A Complete Tutorial for Beginners LIEW VOON KIONG I A Complete Tutorial for Beginners LIEW VOON KIONG Disclaimer II Visual Basic 2008 Made Easy- A complete tutorial for beginners is an independent publication and is not affiliated with, nor has it been

More information

Lecture 5. Review from last week. Selection Statements. cin and cout directives escape sequences

Lecture 5. Review from last week. Selection Statements. cin and cout directives escape sequences Lecture 5 Selection Statements Review from last week cin and cout directives escape sequences member functions formatting flags manipulators cout.width(20); cout.setf(ios::fixed); setwidth(20); 1 What

More information

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) Technology & Information Management Instructor: Michael Kremer, Ph.D. Database Program: Microsoft Access Series DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) AGENDA 3. Executing VBA

More information

PROGRAMMING ASSIGNMENT: MOVIE QUIZ

PROGRAMMING ASSIGNMENT: MOVIE QUIZ PROGRAMMING ASSIGNMENT: MOVIE QUIZ For this assignment you will be responsible for creating a Movie Quiz application that tests the user s of movies. Your program will require two arrays: one that stores

More information

Chapter 4: Control structures

Chapter 4: Control structures Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition

More information

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1 Chapter 2 Input, Processing, and Output Fall 2016, CSUS Designing a Program Chapter 2.1 1 Algorithms They are the logic on how to do something how to compute the value of Pi how to delete a file how to

More information

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

Repe$$on CSC 121 Spring 2017 Howard Rosenthal Repe$$on CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Learn the following three repetition structures in Java, their syntax, their similarities and differences, and how to avoid common errors when

More information

Control Structure: Selection

Control Structure: Selection Control Structure: Selection Knowledge: Understand various concepts of selection control structure Skill: Be able to develop a program containing selection control structure Selection Structure Single

More information

3 The L oop Control Structure

3 The L oop Control Structure 3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement

More information

Lab 3 The High-Low Game

Lab 3 The High-Low Game Lab 3 The High-Low Game LAB GOALS To develop a simple windows-based game named High-Low using VB.Net. You will use: Buttons, Textboxes, Labels, Dim, integer, arithmetic operations, conditionals [if-then-else],

More information

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

More information

ECE 463 Lab 1: Introduction to LabVIEW

ECE 463 Lab 1: Introduction to LabVIEW ECE 463 Lab 1: Introduction to LabVIEW 1. Introduction The purpose of the lab session of ECE463 is to apply/practice the digital communication theory on software-defined radios (USRPs). USRP is coupled

More information

Exercise 1 Using Boolean variables, incorporating JavaScript code into your HTML webpage and using the document object

Exercise 1 Using Boolean variables, incorporating JavaScript code into your HTML webpage and using the document object CS1046 Lab 5 Timing: This lab should take you approximately 2 hours. Objectives: By the end of this lab you should be able to: Recognize a Boolean variable and identify the two values it can take Calculate

More information

I101/B100 Problem Solving with Computers

I101/B100 Problem Solving with Computers I101/B100 Problem Solving with Computers By: Dr. Hossein Hakimzadeh Computer Science and Informatics IU South Bend 1 What is Visual Basic.Net Visual Basic.Net is the latest reincarnation of Basic language.

More information

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm. CHAPTER 1&2 OBJECTIVES After completing this chapter, you will be able to: Understand the basics and Advantages of an algorithm. Analysis various algorithms. Understand a flowchart. Steps involved in designing

More information

Numerical Methods in Scientific Computation

Numerical Methods in Scientific Computation Numerical Methods in Scientific Computation Programming and Software Introduction to error analysis 1 Packages vs. Programming Packages MATLAB Excel Mathematica Maple Packages do the work for you Most

More information

Repe$$on CSC 121 Fall 2015 Howard Rosenthal

Repe$$on CSC 121 Fall 2015 Howard Rosenthal Repe$$on CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while

More information

IT Introduction to Programming for I.T. Midterm Exam #1 - Prof. Reed Spring 2008

IT Introduction to Programming for I.T. Midterm Exam #1 - Prof. Reed Spring 2008 IT 101 - Introduction to Programming for I.T. Midterm Exam #1 - Prof. Reed Spring 2008 What is your name?: (0 points) There are two sections: I. True/False..................... 20 points; ( 10 questions,

More information

You will have mastered the material in this chapter when you can:

You will have mastered the material in this chapter when you can: CHAPTER 6 Loop Structures OBJECTIVES You will have mastered the material in this chapter when you can: Add a MenuStrip object Use the InputBox function Display data using the ListBox object Understand

More information

IMS1906: Business Software Fundamentals Tutorial exercises Week 5: Variables and Constants

IMS1906: Business Software Fundamentals Tutorial exercises Week 5: Variables and Constants IMS1906: Business Software Fundamentals Tutorial exercises Week 5: Variables and Constants These notes are available on the IMS1906 Web site http://www.sims.monash.edu.au Tutorial Sheet 4/Week 5 Please

More information

Chapter Two: Program Design Process and Logic

Chapter Two: Program Design Process and Logic Chapter Two: Program Design Process and Logic 2.1 Chapter objectives Describe the steps involved in the programming process Understand how to use flowchart symbols and pseudocode statements Use a sentinel,

More information

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Copyright 1992-2012 by Pearson Copyright 1992-2012 by Pearson Before writing a program to solve a problem, have

More information

Previously. Iteration. Date and time structures. Modularisation.

Previously. Iteration. Date and time structures. Modularisation. Lecture 7 Previously Iteration. Date and time structures. Modularisation. Today Pseudo code. File handling. Pseudo code Pseudocode is an informal high-level description of the operating principle of a

More information

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions. Introduction In the programs that we have dealt with so far, all statements inside the main function were executed in sequence as they appeared, one after the other. This type of sequencing is adequate

More information

Visual Basic Course Pack

Visual Basic Course Pack Santa Monica College Computer Science 3 Visual Basic Course Pack Introduction VB.NET, short for Visual Basic.NET is a language that was first introduced by Microsoft in 1987. It has gone through many changes

More information

5.1. Examples: Going beyond Sequence

5.1. Examples: Going beyond Sequence Chapter 5. Selection In Chapter 1 we saw that algorithms deploy sequence, selection and repetition statements in combination to specify computations. Since that time, however, the computations that we

More information

Loop Structures. Loop Structures. Algorithm to record 5 TV programmes. Recall Structured Programming..3 basic control structures.

Loop Structures. Loop Structures. Algorithm to record 5 TV programmes. Recall Structured Programming..3 basic control structures. Loop Structures Recall Structured Programming..3 basic control structures Sequence Input -> Process -> Output Selection IF ENDIF SELECT CASE END SELECT Loop Structures DO WHILE LOOP DO LOOP UNTIL FOR NEXT

More information

Chapter 5 Conditional and Iterative Statements. Statement are the instructions given to the computer to perform any kind of action.

Chapter 5 Conditional and Iterative Statements. Statement are the instructions given to the computer to perform any kind of action. Chapter 5 Conditional and Iterative Statements Statement Statement are the instructions given to the computer to perform any kind of action. Types of Statement 1. Empty Statement The which does nothing.

More information

Visual C# Program: Temperature Conversion Program

Visual C# Program: Temperature Conversion Program C h a p t e r 4B Addendum Visual C# Program: Temperature Conversion Program In this chapter, you will learn how to use the following Visual C# Application functions to World Class standards: Writing a

More information

Chapter Overview. More Flow of Control. Flow Of Control. Using Boolean Expressions. Using Boolean Expressions. Evaluating Boolean Expressions

Chapter Overview. More Flow of Control. Flow Of Control. Using Boolean Expressions. Using Boolean Expressions. Evaluating Boolean Expressions Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Copyright 2011 Pearson Addison-Wesley. All rights reserved.

More information

School of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn

School of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn CPS109 Course Notes 6 Alexander Ferworn Unrelated Facts Worth Remembering Use metaphors to understand issues and explain them to others. Look up what metaphor means. Table of Contents Contents 1 ITERATION...

More information

LECTURE 04 MAKING DECISIONS

LECTURE 04 MAKING DECISIONS PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 04 MAKING DECISIONS

More information

Information Science 1

Information Science 1 Topics covered Information Science 1 Fundamental Programming Constructs (1) Week 11 Terms and concepts from Week 10 Flow of control and conditional statements Selection structures if statement switch statement

More information

Start Visual Basic. Session 1. The User Interface Form (I/II) The Visual Basic Programming Environment. The Tool Box (I/II)

Start Visual Basic. Session 1. The User Interface Form (I/II) The Visual Basic Programming Environment. The Tool Box (I/II) Session 1 Start Visual Basic Use the Visual Basic programming environment Understand Essential Visual Basic menu commands and programming procedure Change Property setting Use Online Help and Exit Visual

More information

Statements execute in sequence, one after the other, such as the following solution for a quadratic equation:

Statements execute in sequence, one after the other, such as the following solution for a quadratic equation: Control Structures Sequence Statements execute in sequence, one after the other, such as the following solution for a quadratic equation: double desc, x1, x2; desc = b * b 4 * a * c; desc = sqrt(desc);

More information

Information Science 1

Information Science 1 Information Science 1 Fundamental Programming Constructs (1) Week 11 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 10 l Flow of control

More information

Software Development. Designing Software

Software Development. Designing Software Software Development Designing Software Modules Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such

More information