MIC305 Week 6 Beyond controls Review of properties Differences with VB6: using classes and instances Programming constructs.

Slides:



Advertisements
Similar presentations
Chapter 6 - VB 2005 by Schneider1 Do Loop Syntax Do While condition statement(s) Loop Condition is tested, If it is True, the loop is run. If it is False,
Advertisements

CS 4 Intro to Programming using Visual Basic Do Loops Patchrawat Uthaisombut University of Pittsburgh 1 based on lecture notes by D. Schneider.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Practical Programming COMP153-08S Lecture: Repetition Continued.
CS0004: Introduction to Programming Repetition – Do Loops.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
Slide 1 VB Program Flow Control. Slide 2 Making Decisions v Decision Statement: control the execution of parts of the program based on conditions. v The.
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 1. Introduction Control Structures If / Then Selection Structure If / Then / Else Selection Structure While Repetition Structure.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
5.05 Apply Looping Structures
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
5-1 Chapter 5 The Repetition Process in VB.NET. 5-2 Learning Objectives Understand the importance of the repetition process in programming. Describe the.
ENGR 112 Decision Structures.
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
Tutorial 6 The Repetition Structure
Chapter 4 Looping Statements Adapted From: Starting Out with Visual Basic 2008 (Pearson)
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Overview of VBA Programming & Syntax. Programming With Objects u Objects –Properties: attributes or characteristics of an object (e.g., font size, color,
259 Lecture 11 Spring 2013 Advanced Excel Topics – Loops.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
JavaScript, Fourth Edition
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
CW-V1 SDD 0901 Principals of Software Design and Development Loops Starter: Water JugsWater Jugs.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
4-1 Chapter 4 The Selection Process in VB.NET. 4-2 Learning Objectives Understand the importance of the selection process in programming. Describe the.
Looping Structures Do Loops, For Next Do...Loop While structures check the condition after executing the code and repeat a code block until the test.
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
Controlling Program Flow with Looping Structures
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Practical Programming COMP153-08S Lecture: 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.
Loop Blocks Chapter 6 Part A. Program Blocks 1.Actions- commands, messages, methods 2.Branches- decisions to be made 3.Loops- actions to be repeated.
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Chapter 6 Controlling Program Flow with Looping Structures.
Computer Science Up Down Controls, Decisions and Random Numbers.
UNIT 5 Lesson 15 Looping.
Advanced Excel Topics – Loops
Visual Basic 6 (VB6) Data Types, And Operators
Control Structures: Part 2
3rd prep. – 2nd Term MOE Book Questions.
3rd prep. – 2nd Term MOE Book Questions.
Boolean Expressions and If statements
حلقات التكرار.
Chapter (3) - Looping Questions.
Introduction to Problem Solving and Control Statements
Presentation transcript:

MIC305 Week 6 Beyond controls Review of properties Differences with VB6: using classes and instances Programming constructs

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MessageBox.Show("Hello") End Sub

Displaying the message

Closing a form in VB.Net '---uses another instance of it Dim frm2 As New Form2 frm2.Show() In VB.NET Whidbey, there is no need to create an instance of another form before you can display it. You can open it directly (just as you can in VB6) using its default instance: '---default instance

Review of program constructs Selection and repetition

Programming constructs Select Case –For multiple instances of If….then Loop structures –For..next –Do..until –Do….while

The if Statement If….then….else The if statement is used to control the flow of execution down one of two or more paths, depending on the result of a logical test. Further conditions may be specified with else if, should previous conditions be false, and else may be used should none of the above be true.

Select Case Select Case test expression Case expression-1...this is the code that executes if expression-1 matches test_expression Case expression-2...this is the code that executes if expression-2 matches test_expression Case expression-3...this is the code that executes if expression-3 matches test_expression Case Else...this is the code that executes if expression-n matches test_expression End Select

Example: a tourist information site Suppose you want to give some simple information about counties depending on what the user types in: Eg they want to know about Co Durham or Northumberland

VB.NET code for the above which object do you attach this to? Dim County As String County = txtInputCounty.Text Select Case County Case "Northumberland" MsgBox ("Northumberland is a beautiful county to visit if you enjoy relaxing countryside.") Case "Co Durham" MsgBox ("Visit the Co Durham for a wide variety of scenary from coastal to the historic city of Durham.") Case "Yorkshire" MsgBox ("Yorkshire is Heartbeat country") Case "Cumbria" MsgBox ("Cumbria is noted for its spectacular mountains scenary and lakes.") Case Else MsgBox ("No specific information is available about this county.") End Select End Sub

Using Control Structures to Make Code Repeat To write code that repeats some set of statements – for example when you need to perform some calculation over and over or when you have to apply the same calculations or processing to more than one variable. This section shows you all the control structures you can use in VBA to control code in your program that repeats.

For…Next For counter = 1 to 10 x = x + 5 msgbox x Next

Example Dim x As Integer Dim counter As Integer x = Val(txtInput.Text) For counter = 1 To 10 Step 1 x = x + 2 MsgBox x Next End Sub Event is triggered when the visible form (called the detail) is clicked Variables declared For..next loop, events keep occurring until end of loop

Do While…Loop Do While condition...code within the loop goes here Loop

Exercise We need 6 people One is the counter 5 are the students in the game

Example of Do While First open a new form Put a command button the form called cmdNum Put a textbox on the form called txtOutput InputProcessOutput A numberCheck if it is less than 15, loop if not The number or finished message

Example of do…while Dim x As Integer Do While x < 15 x = InputBox("Enter a number") txtOutput.text = x Loop txtOutput.text="finished"

Runs where the condition is either true or false. As long as the condition is true, the code within the loop gets executed. Once the condition becomes false, the loop stops and the code after the loop is executed. The only way for the program to break out of the loop is if the condition becomes false or if an Exit Do statement is encountered somewhere inside the loop.

Review Constructs –how useful for programming games Next week OO programming: using classes