CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1A) UTPA – Fall 2011.

Slides:



Advertisements
Similar presentations
2.1 Program Construction In Java
Advertisements

Introduction to C Programming
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
 2002 Prentice Hall. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Control Structures: Getting Started Sequence and Selection also arithmetic operators, data types, logical operators.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection Statement 4.6 if else Selection Statement 4.7 while.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
JavaScript, Fourth Edition
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
VB .NET Programming Fundamentals
The University of Texas – Pan American
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
CIS Computer Programming Logic
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
Lecture Set 5 Control Structures Part A - Decisions Structures.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Input, Output, and Processing
Chapter 2: Using Data.
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B) UTPA – Fall 2011.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure 4.6 The if / else Selection Structure 4.7.
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
Introduction to Problem Solving and Control Statements.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Introduction to Programming Lecture 2 Msury Mahunnah, Department of Informatics, Tallinn University of Technology.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
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.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Introduction to Programming Lecture 2
BASIC ELEMENTS OF A COMPUTER PROGRAM
Visual Basic Variables
ITEC113 Algorithms and Programming Techniques
Java Programming: From Problem Analysis to Program Design, 4e
Control Structures in VB
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I UTPA – Fall 2012 This set of slides is revised from lecture slides.
Chapter 2: Basic Elements of Java
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.
Chapter 3: Introduction to Problem Solving and Control Statements
Chapter (3) - Looping Questions.
Control Structures in VB
Chapter 4 - Control Structures: Part 1
DATA TYPES There are four basic data types associated with variables:
Presentation transcript:

CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1A) UTPA – Fall 2011

Objectives In this chapter, you will: –Learn the primitive data types in Visual Basic –Become familiar with arithmetic operators –Explore how to design algorithms to solve problems –Learn the components of basic control structures –Study the syntax of basic sequence, selection, and repetition structures in Visual Basic 2

Introduction Computer program –Sequence of statements whose objective is to accomplish a task Programming –Process of planning and creating a program 3

Introduction (cont'd) Function –Collection of statements; when executed, accomplishes something Syntax –Rules that specify which statements (instructions) are legal Programming language –A set of rules, symbols, and special words –Visual Basic 4

Introduction (cont'd) Reserved words, keywords, or word symbols –Words that are reserved by Visual Basic –Usually in blue color in the IDE (Visual Studio) 5

Primitive Data Types in Visual Basic Boolean Byte Char Date Decimal Double Integer Long 6 SByte Short Single String Uinteger Ulong UShort

Declaration of Variables All variables must be declared before they are used in a program Declaring a variable –Dim number1 As Integer –Dim number2 As Integer Declaring multiple variables of the same type –Dim number1, number2 As Integer 7

Naming Convention Camel case –Variable / function name –E.g., taxRate, salaryPayment Control naming convention –Variable name = the meaning of control's value+ control's type –E.g., number1Label, number2TextBox Although the variable/function name is not case sensitive, it is important to follow a consistent naming convention 8

Arithmetic Operators in Visual Basic Addition: + Subtraction: - Multiplication: * Division (floating point): / Division (integer): \ Modulus: Mod Exponentiation: ^ 9

Division Division (floating point) – x / y –E.g., 7.l / 4 evaluates to

Division (cont'd) Division (integer) –x \ y –x and y are integers 7\4 evaluates to 1, and 17\5 evaluates to 3 –x and y are not integers Numbers are first rounded to the nearest whole number E.g., 7.1 is rounded to 7, and 7.7 is rounded to 8 Thus, 7.1\4 evaluates to 1, and 7.7\4 yields 2 11

Modulus & Exponentiation Modulus –r Mod s –7 Mod 3 evaluates to 1 (since 7=3*2+1) Exponentiation –3^2 evaluates to 3*3=9 –2^3 evaluates to 2*2*2=8 –2^10 evaluates to

Sign Operations Unary Minus –-e –E.g., -10, Unary Plus –+g –E.g., +100 (equivalent to 100) 13

Rules of Operator Precedence ^ +, - (sign operations) *, / \ Mod +, - (addition and subtraction) If there are several operators of the same priority, then they are evaluated from left to right 14 priority high low

Exercises What are the values of the following expressions? –5.2/2 –9 Mod 3 –4\2 –4.4\2 What is the order of the following expression? –X = 2 * 5 ^ *

Comparison Operators Equality operators –= (equal) –<> (not equal) Relational operators –> –< –>= –<= 16

Rules of Operator Precedence ^ +, - (sign operations) *, / \ Mod +, - (addition and subtraction) =, <>,, >= (equality and relational) 17 priority high low

Example 3.27: Comparison.vb URL: _htp_2010/codeexamples.html _htp_2010/codeexamples.html TextBox –Set MultiLine property to true –AppendText method –vbCrLf – press an "enter" key 18

Problem Solving Techniques Problem-solving process has three steps: –Analyze problem and design an algorithm –Implement the algorithm in code –Maintain the program Algorithm is independent of languages –Actions to be executed, and –The order in which these actions are executed Pseudo code 19

Control Structures Problem with the GoTo statement –GoTo statement can specify a control to any place (line or destination) in a program –Making the program unstructured and hard to follow Research indicates that all programs can be written by only 3 control structures –With "GoTo elimination" 20

Categories of Control Structures Control Structures –Sequence structure –Selection structure –Repetition structure 21

Sequence Structure Visual Basic statement –total = total + grade –counter=counter+1 UML activity diagram –Flowchart –Initial state  action state 1  …  action state n  final state 22 Add grade to total Add 1 to counter

Selection Structure If … Then If … Then … Else Select … Case 23 display "passed" [grade>=60] [grade<60]

Selection (1) If … Then –If grade >= 60 Then write(“Passed”) End If 24

Selection (2) If … Then … Else –If grade >= 60 Then write(“Passed”) Else write (“Failed”) End If 25

Nested Selection If grade >= 90 Then write(“A”) Else If grade >= 80 Then write(“B”) Else If grade >= 70 Then write(“C”) Else write(“F”) End If 26

Alternative Version If grade >=90 Then write (“A”) ElseIf grade >=80 Then write(“B”) ElseIf grade >= 70 Then write(“C”) Else write(“D”) End If 27

Repetition Structure Visual Basic provides 7 repetition statements –Do While … Loop –While … End While –Do Until … Loop –Do … Loop While –Do … Loop Until –For … Next –For Each … Next 28

Example of Repetition See example programs –Do While … Loop –Find the first power of 3 larger than triple the product value [product<=100] [product>100] decision merge

Example of Repetition (cont'd) While + loop-continuation condition Do While product <=100 product = product * 3 ' compute next power of 3 Loop While product <=100 product = product * 3 ' compute next power of 3 End While 30

Example of Repetition (cont'd) Until + loop-termination condition Do Until product > 100 product = product * 3 ' compute next power of 3 Loop 31

Example 4.12: ClassAverage.vb URL: _htp_2010/codeexamples.html _htp_2010/codeexamples.html ListBox –gradeListBox.Items.Add(gradeTextBox.Text) –gradeListBox.Items(gradeCounter) –gradeListBox.Items.Count 32

33