CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
Control Structures: Getting Started Sequence and Selection also arithmetic operators, data types, logical operators.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Problem Solving and Control Statements. Using Exit to Terminate Repetition Statements There are many forms of the Exit statement, designed to terminate.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B) UTPA – Fall 2011.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #5 Control Statements: Part 2.
Controlling Program Flow with Looping Structures
5.1 Introduction Problem Solving –Requires understanding of: Building blocks Program-construction principles BZUPAGES.COM.
Input Boxes, List Boxes, and Loops Chapter 5. 2 Input Boxes Method for getting user’s attention to obtain input. InputBox() for obtaining input MessageBox()
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
Chapter 4 Select … Case Multiple-Selection Statement & Logical Operators 1 © by Pearson Education, Inc. All Rights Reserved. -Edited By Maysoon.
 2007 Pearson Education, Inc. All rights reserved Control Statements: Part2.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.-Edited By Maysoon Al-Duwais1.
Repetition statements
Problem Solving and Control Statements: Part 2
Lecture 4b Repeating With Loops
Chapter 5- Control Structures: Part 2
Lecture 7: Repeating a Known Number of Times
Problem Solving and Control Statements: Part 2
Control Statements: Part 2
Control Structures: Part 2
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
JavaScript: Control Statements.
Chapter 5 – Control Structures: Part 2
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Control Structures: Part 1
MSIS 655 Advanced Business Applications Programming
The University of Texas Rio Grande Valley
The University of Texas – Pan American
Outline Altering flow of control Boolean expressions
The University of Texas – Pan American
Chapter 8 JavaScript: Control Statements, Part 2
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
The University of Texas – Pan American
CSCI 3327 Visual Basic Review: Final Exam
The University of Texas – Pan American
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
3 Control Statements:.
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 6 Control Statements: Part 2
Introduction to Problem Solving and Control Statements
CSCI 3327 Visual Basic Review: Exam I
Problem Solving and Control Statements
Fundamentals of visual basic
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Case & Repetitive Statements
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Presentation transcript:

CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous lecture slides. – Xiang Lian

Objectives In this chapter, you will do exercises related to: Usage of control structures in Visual Basic Logical operators

Exercises Which property specifies whether a CheckBox is selected? 1. Selected 2. Checked 3. Clicked 4. Check Call the _____method of class MessageBox to display a message dialog. 1. Display 2. Message 3. Open 4. Show A unary operator ______. 1. requires exactly one operand 2. requires two operands 3. must use the AndAlso keyword 4. can have no operands The ____ operator is used to ensure that two conditions are both true. 1. Xor 2. AndAlso 3. Also 4. OrElse The Do…Loop While statement body repeats when the loop-continuation condition _____. 1. is False after the body executes 2. is False before the body executes 3. is True after the body executes 4. is True before the body executes An infinite loop occurs when the loop-continuation condition in a Do While…Loop or Do…Loop While statement______. 1. never becomes True 2. never becomes False 3. is False 4. is tested repeatedly

Exercises (cont'd) The Do…Loop Until statement checks the loop-termination condition _______. 1. for False after the body executes 2. for False before the body executes 3. for True after the body executes 4. for True before the body executes Counter-controlled repetition ____ the control variable after each iteration. 1. increments 2. initialize 3. decrements 4. either answer 1 or 3 What aspect of the control variable determines whether looping should continue? 1. name 2. initial value 3. type 4. final value If the step is omitted, the increment of a For…Next statement defaults to ______. 1. 1 2. -1 3. 0 4. Either answer 1 or 2 Which of the following is the appropriate For…Next header for varying the control variable over the following sequence of values: 25, 20, 15, 10, 5? 1. For i As Integer = 5 To 25 Step 5 2. For i As Integer = 25 To 5 Step -5 3. For i As Integer = 5 To 25 Step -5 4. For i As Integer = 25 To 5 Step 5

Exercises (cont'd) A Case that handles all values larger than a specified value must precede the > operator with keyword ______. 1. Select 2. Is 3. Case 4. All Use a(n) _____ to separate multiple conditions in a Case statement. 1. period 2. asterisk 3. comma 4. colon The ______property determines by how much the current number in a numericUpDown control changes when the user clicks the up arrow or down arrow. 1. Amount 2. Step 3. Increment 4. Next Which For…Next header alters the control variable from 0 to 50 in increment of 5? 1. For i = 0 To 50 Step 50 2. For 0 To 50 Step 5 3. For i = 0 To 50 Step = 5 4. For i = 0 To 50 Step 5

Select…Case Statement Relational operator Case Is < 0 Case Is >100 Multiple values Case 0, 5 To 9 ' 0 and range 5 ~ 9

True/False Statements The Case Else is required in the Select…Case selection statement. The expression x>y And a<b is true if either x>y is true or a<b is true. An expression containing the Or operator is true if either or both of its operands are true The expression x<=y AndAlso y>4 is true if x is less than or equal to y and y is greater than 4 Logical operator Or performs short-circuit evaluation.

True/False Statements (cont'd) The Exit Do, Exit For and Exit While statements, when executed in a repetition statement, cause immediate exit from only the current iteration of the repetition statement. The Do…Loop While statement tests the loop-continuation condition before the loop body is performed. The Or operator has a higher precedence than the And operator.

What Does the Code Do? Dim y As Integer Dim x As Integer Dim mysteryValue As Integer x=1 mysteryValue=0 Do y = x^2 'What is the value of y in the first iteration? displayListBox.Items.Add(y) mysteryValue += 1 x += 1 Loop While x<=10 resultLabel.Text = mysteryValue 'What is the value of resultLabel.Text? 'What are values of the displayListBox? 'What is the value of x?

What is Wrong in the Code? Dim y As Integer = 5 Dim z As Integer = 1 Do z*=y Loop Until y < 1 y -=1 resultLabel.Text = z

What is Wrong in the Code? Determine whether an Integer is even or odd Select Case value Mod 2 Case 0 outputLabel.Text = "Odd Integer" Case 1 outputLabel.Text = “Even Integer" 2 errors

Write a Program Use For … Next to write a program to display the triangle of asterisks in outputTextBox. Use the following statements: outputTextBox.AppendText("*"):displays asterisks one at a time outputTextBox.AppendText(vbCrLf) outputTextBox.AppendText(" "): inserts a space * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Write a Program (cont'd) Use For … Next to write a program to display a rectangle in outputTextBox. Use the following statements: outputTextBox.AppendText("+") outputTextBox.AppendText(vbCrLf) outputTextBox.AppendText(" "): inserts a space + - - - - - - - - - - + | |

Exercises After the Class Chapter 5 in your textbook Self-Review Exercises Quick Quiz Exercises