COM148X1 Interactive Programming Lecture 8. Topics Today Review.

Slides:



Advertisements
Similar presentations
CS0004: Introduction to Programming Select Case Statements and Selection Input.
Advertisements

RAPTOR Syntax and Semantics By Lt Col Schorsch
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
COM148X1 Interactive Programming Lecture 5. Topics Today Flowchart Pseudo-Code Design Approach Array Collection.
1.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
VBA Modules, Functions, Variables, and Constants
Control structures Part 2 iteration control To enable repetition of a statement block.
Python quick start guide
Apply Sub Procedures/Methods and User Defined Functions
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
IE 212: Computational Methods for Industrial Engineering
Chapter 6 Procedures and Functions Instructor: Bindra Shrestha University of Houston – Clear Lake CSCI
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
COM148X1 Interactive Programming Lecture 3. Topics Today String Functions Using Timer Looping.
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
COM148X1 Interactive Programming Lecture 6. Topics Today Generate Random Numbers Graphics Animation.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
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.
Chapter 6 Sub Procedures
Arrays Code: Arrays Controls: Control Arrays, PictureBox, Timer.
COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling.
Visual Basic Programming
Applications Development
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
PSU CS 106 Computing Fundamentals II VB Declarations HM 5/4/2008.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Debugging, Static Variables, ByRef, ByValue Chapt. 6 in Deitel, Deitel and Nieto.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
Programming games in Visual Basic Review programming & VB topics Insertion sort. Best times. Generate questions & answer patterns for quiz Lab/Homework:
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
List Boxes and Combo Boxes Provides a list of items to select from Various styles — choose based on Space available Need to select from an existing list.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Practical Programming COMP153-08S Lecture: Repetition.
Controlling Program Flow with Decision Structures.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Loop and repetition. Today Passing values to and back from Sub procedures Option Buttons Do While Loops For Loops Population Growth.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
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.
Computer Science Up Down Controls, Decisions and Random Numbers.
TUTORIAL 4 Visual Basic 6.0 Mr. Crone. Pseudocode Pseudocode is written language that is part-code part- English and helps a programmer to plan the layout.
REEM ALMOTIRI Information Technology Department Majmaah University.
COM148X1 Interactive Programming Lecture 4. Topics Today DateTime Functions Using Module Using Procedure Using Function Pass by Value and Pass by Reference.
Sub Procedures And Functions
Programming Right from the Start with Visual Basic .NET 1/e
VISUAL BASIC 6.0 Designed by Mrinal Kanti Nath.
Lesson 16 Sub Procedures Lesson 17 Functions
JavaScript: Functions
Computer Programming I
Microsoft Visual Basic 2005 BASICS
Chapter 6 Sub Procedures
Introduction to Problem Solving and Control Statements
Faculty of Computer Science & Information System
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
STARTING OUT WITH Visual Basic 2008
Presentation transcript:

COM148X1 Interactive Programming Lecture 8

Topics Today Review

Let’s Recall What Have Learnt Variable Declaration Basic Operators Branching and Looping Function and Procedure Flowchart Array and Collection Random Number Generation Timer PictureBox and ImageList Control Graphics and Animation HCI Event Handling

Variable Declaration Use keyword Dim in Visual Basic to declare variable Dim variable_name_list As data_type variable_name_list is the list of variable names separated by comma data_type is can be one of the data types mentioned in previous page or user defined data types Example Dim a As Integer Dim b, c As Double

Arithmetic Operators OperationVB OperatorVB Expression Addition+x + y Subtraction-x - y Multiplication*x * y Division/x / y Integer Division (quotient)\x \ y Exponentiation^x ^ y Modulus (remainder)Modx Mod y String Concatenation&x & y

Comparison Operators OperationVB OperatorVB Expression ==x = y  <>x <> y >>x > y <<x < y  >=x >= y  <=x <= y

And Operator (condition 1) And (condition 2) The expression is TRUE if and only if both condition 1 and condition 2 are TRUE Example (x > 10) And (x < 10000) ‘True if 10 < x < 10000

Or Operator (Condition 1) Or (Condition 2) The expression is FALSE if and only if both Condition 1 and Condition 2 are FALSE Example (y 10000) ‘True if y greater than 10 ‘or y smaller than 10000

Xor Operator (condition 1) Xor (condition 2) The expression is TRUE if and only if condition 1 and condition 2 give different results, that is condition 1 is TRUE while condition 2 is FALSE or vice versa Example (x > 1000) Xor (y > 1000) ‘True if x > 1000 but y ≤ 1000 ‘or x ≤ 1000 but y > 1000

Not Operator Not (condition) The expression is TRUE if and only if the given condition is FALSE Example Not (student > 100) ‘True if student smaller than 100

Branching Branching is a program control structure which allows computer executes different parts of program according to user inputs or computation results In Visual Basic, branching can be done by If Else statement or Select Case statement

Combination of Conditions Sometimes the condition is based on combination of many conditions, for example, checking the value of variable x within a range (a, b) Use operators And, Or, Xor, Not to combine different conditions

Looping Looping is a program control structure which allows computer executes part of program multiple times In Visual Basic, looping can be done by For Next loop or Do While loop

Procedure Procedure is a segment of code which responsible for a sub-task of the main task Advantages of using procedure Make the program easy to design and implement Make the code easy to reuse Make the code easy to read Make the code easy to modify

Define Procedure Sub procedure_name( ByVal pname1 As ptype1, … ) procedure End Sub Example Sub AddStock(ByVal stock_count As Integer) total_cost = total_cost + stock_count * 5 End Sub

Function Function is similar to procedure but it will return a value back to the caller

Define Function Function function_name( ByVal pname As ptype, … ) As output_type function calculation function_name = value End Function Example Function CheckCode(ByVal code As Integer) As Boolean If code 100 Then CheckCode = False Else CheckCode = True End If End Function

Pass By Value If parameters set as ByVal, then it is “Pass by Value”, all modifications to this parameter during the execution of function/ procedure will not retain (i.e. the value of the parameter will be restored back to the value before the function/ procedure execute)

Pass by Reference If parameters set as ByRef, then it is “Pass by Reference”, all modifications to this parameter during the execution of function/ procedure will retained

Terminal used to represent the start/ end of the program Input/ Output Process Decision Connector used to connect different parts of flowchart when the direct connection among these parts are messy Flowchart Symbols

What is Array Array is a collection of data of same type Size of array is fixed unless it is being asked to change Array is random access Index of array start from 0

UBound Function Obtain the largest index of an array Example For j = 0 To UBound(a) a(i) = 20 Next j 20 a

What is Collection Collection is a group of data which can be retrieved either by index or string Collection index started from 1 Dim collection_name As New Collection() Example Dim marks As New Collection()

Generate Random Number In VB, random numbers can be generated using Rnd() function Rnd() function returns random number in the range [0 … 1) (include 0 but exclude 1) Example x = Rnd() ‘0 ≤ x < 1 x = Rnd() * 5 ‘0 ≤ x < 5 x = Int(Rnd() * 5) + 1 ‘1 ≤ x ≤ 5, integer only

Randomize() Function The number sequence generated by Rnd() will be the same when the application start Randomize() function is used to shuffle the sequence again Call Randomize() once when the application start

Pseudo Random Number Sometimes, non-repeatable random number is required, for example, shuffle a deck of card (A, 2, 3, …, J, Q, K) Use the technique called pseudo random number to generate non-repeatable random number

Pseudo Random Number Algorithm Use array to store all number Use Rnd() function to pick two array position randomly and then SWAP the content Repeat the step above several times and use the array as random result

Pseudo Random Number Example Dim cards(13) As Integer Dim j, k, card1, card2 As Integer For j = 1 To 13 cards(j) = j Next j PseudoRandom(cards)

Pseudo Random Number Example (cont’) ‘Perform pseudo random from 1 … UBound(a) Sub PseudoRandom(ByRef a() As Integer) For k = 1 to card1 = Int(Rnd() * UBound(a)) + 1 card2 = Int(Rnd() * UBound(a)) + 1 Swap(a(card1), a(card2)) Next k End Sub

Pseudo Random Number Example (cont’) Sub Swap(ByRef x As Integer, ByRef y As Integer) Dim temp As Integer = x x = y y = temp End Sub

Timer Timer is an invisible stopwatch to do count down from present time Once timer finished count down, corresponding code set by programmer will be executed

Timer Properties Enabled Count down will start if it is True Interval Number of milliseconds for count down, once finished count down, call-back function (written by programmer himself) will be executed

Graphics Example Dim g As Graphics g = Panel1.CreateGraphics() Dim brush1 As New SolidBrush(Color.Red) Dim pen as New Pen(brush1, 10) g.DrawLine(pen, p1, p2) Dim brush2 As New SolidBrush(Color.Green) g.FillRectangle(brush, p1.X(), p1.Y(), 100, 150)

ImageList Images is set of Images, index start from 0 ImageSize is the size of image, maximum size is 256x256 Number of images in the ImageList can be found in the Count properties of Images Example x = ImageList1.Images.Count

PictureBox Location represents the top-left corner of PictureBox Top represents the top most coordinate of PictureBox Left represents the left most coordinate of PictureBox Width represents the width of PictureBox Height represents the height of PictureBox Image represents the picture showing in the PictureBox, set Image to Nothing in order to make the PictureBox shows nothing Example PictureBox1.Image = Nothing

Animation Example ‘move image from left to right while playing ‘image sequence inside PictureBox Dim i As Integer = 0 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim x, y as Integer x = PictureBox1.Location.X + 1 y = PictureBox1.Location.Y PictureBox1.Location = new Point(x, y) PictureBox1.Image = ImageList1.Images(i) i = (i + 1) mod ImageList1.Images.Count End Sub

HCI HCI stands for Human Computer Interaction, it is a field of study of designing user-friendly computer interface Many guidelines available and Apple’s one mainly used for reference during lecture

Event An event is an action which programmer can handle in code An event can be generated by User (clicking a button) System (timer completed count down) Programmer (change the attribute of control) In VB, different control expose different set of event for programmer to handle

Event Handler Event handler is the program which handle specific event(s)