Mr C Johnston ICT Teacher www.computechedu.co.uk BTEC IT Unit 06 - Lesson 05 Learning To Program.

Slides:



Advertisements
Similar presentations
2.1 Program Construction In Java
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Integrated Business Applications with Databases (D3) Jenny Pedler
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Programming in Visual Basic
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Program Design and Development
Control Structures: Getting Started Sequence and Selection also arithmetic operators, data types, logical operators.
VB .NET Programming Fundamentals
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Lesson 2 McManus COP  Computational ◦ problems involving some kind of mathematical processing  Logical ◦ Problems involving relational or logical.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1A) UTPA – Fall 2011.
CIS Computer Programming Logic
Saeed Ghanbartehrani Summer 2015 Lecture Notes #4: Working with Variables and User Interfaces IE 212: Computational Methods for Industrial Engineering.
2440: 211 Interactive Web Programming Expressions & Operators.
Language Elements 1. Data Types 2 Floating Point (real) Single Precision Double Precision Decimal Fixed Point (integer) Byte Short Integer Long Numerical.
BTEC Unit 06 – Lesson 06 Evidencing P4 Mr C Johnston ICT Teacher
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Chapter 2: Using Data.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
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.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.
Variables Continued In the last session we saw how variables are objects that allow us to store values in the RAM of the computer In this session we shall.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
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.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Selection Using IF THEN ELSE CASE Introducing Loops.
G043: Lecture 12 Basics of Software Development Mr C Johnston ICT Teacher
Unit 2 Technology Systems
IE 8580 Module 4: DIY Monte Carlo Simulation
A variable is a name for a value stored in memory.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
COMPUTATIONAL CONSTRUCTS
Visual Basic Variables
Visual Basic 6 (VB6) Data Types, And Operators
The Selection Structure
3rd prep. – 2nd Term MOE Book Questions.
Unit 2 Programming.
Selection CIS 40 – Introduction to Programming in Python
Introduction to C++ Programming
Chapter (3) - Looping Questions.
T. Jumana Abu Shmais – AOU - Riyadh
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
We’re moving on to more recap from other programming languages
Coding Concepts (Basics)
ICT Gaming Lesson 3.
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Chapter 2 Programming Basics.
Unit 3: Variables in Java
Quick Test Professional Training Part 1
Intro to Programming (in JavaScript)
COMPUTING.
Presentation transcript:

Mr C Johnston ICT Teacher BTEC IT Unit 06 - Lesson 05 Learning To Program

Session Objectives Understand the concept of variables in programs and appreciate their use and properties, Understand different programming constructs which can be used to structure programs, Use different program constructs to create small programs to illustrate their use.

Variables All programs at some point will need to store data which is either input or from processing, Although programs often output data to a more permanent form the data still needs to be stored somewhere within the program prior to this, Data is temporarily stored within in a program in a VARIABLE, Variables all have a name and a data type, and need to be defined within the program before they can be used. Dim studentName As String Declares the variable Names the variable Set the data type of the variable

Variable Names When I first started to program we called variables X and Y as name length was limited – hard to tell what they are, Good programming technique now is to use sensible names for our variables to make the code easy to read and maintain, Most language don’t all spaces in variable name so often we use capital letters (studentName) or underscores (student_Name) instead.

Variable Data Types As well as being declared and having a name a variable needs a data type, The data type refers to the type of data which will be stored within the variable. Typical data types used include: Data TypeData UseRange of Values BooleanValues that can be true or falseTrue or False ByteWhole numbers(8 bit) 0 to 255 IntegerWhole numbers(16 bit) -32,768 to +32,767 LongLarge whole numbers c + / - 2x10 9 SingleDecimal numbers (float)Up to 7 significant figures DoubleLarge decimal numbersUp to 14 significant figures DateDate and TimeVariety of date and time formats StringAny type of characterSometimes char limit VbMsgBoxResultResults of msgbox button pressesvbYes, vbNo, vbOK, vbCancel etc

Programming Constructs There a several different programming constructs which make up the structure of a program: Sequence Statements: When the program statements are followed one after another Selection (or decision): When a choice is made based on criteria – usually IF statements Iteration (or repetition): When a section of code is repeated using a loop – there are two main types of loop fixed (repeat until) and conditional (while do)

Visual Basic for Applications 1 Overview To demonstrate some of the programming constructs we are going to use a programming language built into PowerPoint called Visual Basic for Applications (VBA), To access VBA you can either press Alt+F11 or click on the Visual Basic Icon from the developer ribbon.

To start programming within visual basic you first need to create a new module and then define a subroutine or a function to house the code, Subroutine and function names can be anything sensible as long as there are no spaces and a reserved word is not used, Code is then added between the Sub and the End Sub to make the program. Code added here Visual Basic for Applications 2 Modules, Subs and Functions

To declare a variable in visual basic we use the DIM statement. Visual Basic for Applications 3 Declaring Variables Dim [variable name] As [variable type] Data Type Boolean Byte Integer Long Single Double Date String VbMsgBoxResult

Assign data to a variable: [variableName] = [value] Output to screen: MsgBox(“[message]”) OR MsgBox([variableName]) Input value into program: [variableName] = InputBox(“[instruction]”) Concatenate variables and data: [variableName] = “[message] ” & [variableName] & “ [message]” Visual Basic for Applications 4 Sequence Statements 1

Mathematical Operators – As well as concatenating variables we can also manipulate them using mathematical operators. [variableName] = [variableName] [mathsOperator] [variable OR value] Visual Basic for Applications 5 Sequence Statements 2 OperatorData UseExampleOrder of Precedence ^ Raise to power of3 ^ 3 = 271 * Multiply6 * 4 = 242 / Division50 / 5 = 103 Mod Remainder of division10 MOD 3 = 14 + Add = Subtract83 – 47 = 366

IF statements are used to check if a condition has been met If [condition] Then [instructions to be run if true] Else [instructions to be run if false] End If Visual Basic for Applications 6 Selection Statements 1

IF statements can be nested to test if different conditions have been met If [condition] Then [instructions to be run if true] Else IF [instructions to be run if true] Else IF [instructions to be run if both false] End If Visual Basic for Applications 7 Selection Statements 2

Nested IF statements although useful are quite inefficient, and its better to use a SELECT CASE statement Select Case [variable to be used] Case Is [condition] [instructions if true] Case Is [condition] [instructions if true] Case Is [condition] [instructions if true] etc End Select Visual Basic for Applications 8 Selection Statements 3

When creating IF and CASE statements we use operators to construct conditions, Relational operators allow use to construct conditions which compare variables with other values, Logical operators can be used to combine different conditions. Visual Basic for Applications 9 Logical and Relational Operators OperatorMeaning > Greater than < Less than / Equal to >= Greater than or equal to <= Less than or equal to <> Not equal to OperatorMeaningExample AND Returns true if all conditions are true Age > 18 AND Gender=‘F’ OR Returns true if one of the conditions is true Age > 18 OR Gender=‘F’ NOT Returns the opposite of the condition NOT Age > 18

Iteration means repeat or loop, There are two different types of loop we use within programming: Fixed loops – repeat for a fixed number of times Variable loops – repeat until criteria are met Visual Basic for Applications 9 Iteration 1

FOR loops repeat a section of code a stated number of times FOR [counter variable] = [start value] to [end value] [instructions to be run inside loop] Next Visual Basic for Applications 9 FOR Loops

DO loops keeping repeating the instructions until a criteria has been met. Criteria could be WHILE, or UNTIL DO WHILE [variable] [criteria] [instructions to be run inside loop] Loop DO UNTIL [variable] [criteria] [instructions to be run inside loop] Loop Visual Basic for Applications 9 DO Loops