Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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

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

3 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 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 never becomes False is False 4. is tested repeatedly

4 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 ______. 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 For i As Integer = 25 To 5 Step -5 3. For i As Integer = 5 To 25 Step For i As Integer = 25 To 5 Step 5

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 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 For 0 To 50 Step For i = 0 To 50 Step = For i = 0 To 50 Step 5

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

7 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.

8 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.

9 What Does the Code Do? Dim y As Integer Dim x As Integer
Dim mysteryValue As Integer x=1 mysteryValue=0 Do y = x^ '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?

10 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

11 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

12 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 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

13 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 | |

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


Download ppt "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."

Similar presentations


Ads by Google