160 likes | 320 Views
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B). UTPA – Fall 2011. Objectives. In this chapter, you will do exercises related to: Primitive data types in Visual Basic Arithmetic operators Algorithm design Usage of control structures in Visual Basic.
E N D
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B) UTPA – Fall 2011
Objectives • In this chapter, you will do exercises related to: • Primitive data types in Visual Basic • Arithmetic operators • Algorithm design • Usage of control structures in Visual Basic
Compound Assignment Operators • Value = Value + 3 Value +=3 • More compound assignment operators • += • -= • *= • /= • \= • ^= • &=
Example 3.8: Addition.vb • URL: http://media.pearsoncmg.com/ph/esm/deitel/vb_htp_2010/codeexamples.html • TextBox • Change the names of controls • E.g., resultLabel, number1TextBox, number2TextBox, addButton • resultLabel.Text = "The sum is" & total • TextChanged Events • Clear() method
Exercises • The form's _____ property specifies the text that is displayed in the Form's title bar. • 1. Title 2. Text 3. (Name) 4. Name • Property _____ specifies how text is aligned within a Label's boundaries • 1. Alignment 2. AlignText 3. Align 4. TextAlign • An output Label should ______. • 1. be distinguishable from other Labels • 2. initially have an empty Text property or a default value • 3. use Fixed3D for the BorderStyle property • 4. All of the above • A Button's ______ property sets the text on the face of the Button. • 1. Name 2. Text 3. Title 4. Face • If there are errors in an application, they appear in a window known as the _____. • 1. TaskList 2. Output 3. Properties 4. Error List
Exercises (cont'd) • When a value is placed into a memory location, the value ______ the previous value in that location. • 1. copies 2. replaces 3. adds itself to 4. moves • When a value is read from memory, that value is _____. • 1. overwritten 2. replaced with a new value 3. moved to a new location in memory 4. not overwritten • Arithmetic expressions must be written ___to facilitate entering applications into the computer. • 1. using parentheses 2. on multiple lines 3. in straight-line form 4. None of the above • The expression to the right of an assignment operator (=) is evaluated ______the assignment occurs. • 1. before 2. after 3. at the same time 4. none of the above
True/False Statements • Comments cause the computer to print the text after the ' on the screen when the program executes. • All variables must be declared before they can be used in a Visual Basic program. • Visual Basic considers the variable names number and NuMbEr to be different. • The arithmetic operators *, /, + and – all have the same level of precedence. • A string of characters contained between double quotation marks is called a phrase or phrase literal. • Integer division yields an Integer result.
What Does the Code Do? • Dim number1 As Integer • Dim number2 As Integer • Dim result As Integer • number1 = 5*(4+6) 'What is number1? • number2= 2^2 'What is number2? • result =number1 \ number2 'What is result?
What is Wrong in the Code? • Dim number1 As Integer • Dim number2 As Integer • Dim result As Integer • number1 = (4*6^4)/(10 Mod 4 - 2) • number2=(16\3)^2*6+1 • result =number1-number2
Exercises • A(n) ______ is a plan for solving a problem in terms of the actions to be executed and the order in which these actions are to be executed. • 1. chart 2. control structure 3. algorithm 4. ordered list • ____ is an informal language that helps you develop algorithms. • 1. Pseudocode 2. VB-Speak 3. Notation 4. None of the above • Pseudocode_____. • 1. usually describes only declarations 2. is executed on computers 3. usually describes only executable lines of code 4. usually describes declarations and executable lines of code • All Visual Basic applications can be written in terms of ___ types of control structures. • 1. one 2. two 3. three 4. four
Exercises (cont'd) • The process of application statements executing one after another in the order in which they are written is called_______. • 1. transfer of control 2. sequential execution 3. workflow 4. none of the above • The symbol _____ is not a Visual Basic operator. • 1. * 2. ^ 3. % 4. <> • If … Then …Else is a ______-selection statement. • 1. single 2. double 3. triple 4. nested • If "number" is initialized with the value 5, what value will "number" contain after the expression: number-=3 executes? • 1. 3 2. 5 3. 7 4. 2
Exercises (cont'd) • The body of a Do While … Loop statement executes ______. • 1. at least once 2. never 3. while its condition is true 4. while its condition is false • Statements in the body of a Do until … Loop execute repeatedly for as long as the _____ remains False. • 1. loop-continuation condition 2. do-loop condition 3. loop-termination condition 4. until-loop condition
Exercises (cont'd) • Identify errors in the code that totals the values from 1 to 50, assuming that value is 50. • Do While value >=0 • sum+=value • Loop
Exercises (cont'd) • Write a repetition structure that obtains 2^10 (DO NOT use ^ directly).
True/False Statements • Pseudocode is a structured programming language. • The body of a Do While … Loop is executed only if the loop-continuation test is false. • The body of a While … End While is executed only if the loop-continuation test is false. • The body of a Do Until … Loop is executed only if the loop-termination test is false.
Exercises After the Class • Chapters 1~4 in your textbook • Self-Review Exercises • Quick Quiz • Exercises