NOTES: Procedures (module 15)

Size: px
Start display at page:

Download "NOTES: Procedures (module 15)"

Transcription

1 Computer Science 110 NAME: NOTES: Procedures (module 15) Introduction to Procedures When you use a top-down, structured program design, you take a problem, analyze it to determine what the outcome should be and then decide the best way to arrive at that output. Your analysis should result in the development of a series of steps that you must follow to arrive at the desired output. After following these steps from beginning to end, you should arrive at a satisfactory resolution to the problem. For example, you may be presented with the problem of writing a payroll application. You determine that you will need, among other things, a way to calculate the amount of income tax that must be deducted from each employee. In your payroll application, you will use a procedure to calculate the income tax. Visual Basic procedures are used to break problems into manageable sections of code. A procedure is a block of code that performs a specific task. In this module, you will learn how to write both general procedures and function procedures. Sub Procedures To review, a procedure is a block of code that performs a specific task. The now familiar cmddone_click( ) event is an example of a procedure. This procedure performs the task of ending a program. There are two types of Sub procedures: 1. Event procedures, which are referred to as Sub Procedures 2. General procedures, which are user-defined procedures that must be called from an event procedure General Procedures There are many tasks that must be carried out as a program runs. The programmer writes general procedures, or small blocks of code, to carry out each task. Even if a task must be performed many times, the code only needs to be written once. Each procedure that is written simplifies the program by breaking the program down into smaller blocks of code that are easier to work with. Let's look at an example of how a general procedure is used to clear a caption. In this example, a label has a caption. This caption must be cleared several times as the program runs. To do this, the programmer would write a general procedure that contains a block of code to clear the caption. This procedure is then called whenever the caption needs to be cleared. The syntax for a general procedure is shown: The following code shows an example of a general procedure: Sub ClearLabelInstructions( ) lblinstructions.caption = "" A general procedure must be called from another procedure in order to be executed. The Call Statement A general procedure such as the one shown from the previous lesson: Sub ClearLabelInstructions( ) lblinstructions.caption = "" must be called from another procedure in order to be executed. The Call statement is used to execute a general procedure. The following is an example: Private Sub optbeachinstructions_click ( ) Call ClearLabelInstructions Call ToBeach

2 In the event procedure shown above, there are two Call statements (shown in green type). The first one executes the ClearLabelInstructions() general procedure. The second one executes the ToBeach()general procedure (not shown). Let's look at a section of code that contains both the ClearLabelInstructions and the ToBeach procedures. The user interface is as shown above. Notice, in the code that follows, the use of the line continuation character ( _ ) to join long statements from one line to the next. Private Sub Form_Load( ) optconveniencestoreinstructions.value = False optvideostoreinstructions.value = False optbeachinstructions.value = False Private Sub optbeachinstructions_click( ) Call ClearLabelInstructions Call ToBeach Sub ClearLabelInstructions() lblinstructions.caption = "" Sub ToBeach() Call ToOceanViewDrive lblinstructions.caption = lblinstructions.caption & _ "Head east on Ocean View Drive. Beach is to the_ left." & vbcrlf Sub ToOceanViewDrive() Call ToMaplesTrail lblinstructions.caption = lblinstructions.caption &_ "Head south on Maples Trail to Ocean View Drive." &_ vbcrlf Sub ToMaplesTrail() lblinstructions.caption = "Head east on Sunny Lane to_ Maples Trail." _ & vbcrlf When the user clicks the Beach button on the interface, the optbeachinstructions_click event procedure is executed: This procedure calls ClearLabelInstructions to clear the lblinstructions label. When ClearLabelInstructions is finished executing, control of the program passes back to optbeachinstructions_click. The next statement in the optbeachinstructions_click procedure calls the ToBeach procedure. This procedure calls the ToOceanViewDrive procedure. ToOceanViewDrive procedure calls the ToMaplesTrail procedure. ToMaplesTrail procedure assigns to lblinstructions a string of instructions to Maples Trail and a carriage return-line feed. ToOceanViewDrive procedure and ToBeach concatenate additional instructions and a carriage return-line feed to the lblinstructions label. Creating a General Procedure in the Code Window General procedures may be added to the Code window in two ways: 1. Type Sub, followed by the procedure name and then press Enter. Visual Basic then automatically adds an statement and places the cursor in the body of the procedure. 2. With the Code window open, select Tools Add Procedurefrom the menu bar. The Add Procedure command displays a dialogue box, as shown. From the dialogue box, the programmer selects the procedure name, type and scope. After selecting OK, the procedure is placed in alphabetical order in the Code window.

3 Parameters and Passing Arguments by Value A procedure often needs additional data to be able to complete its task. The extra data is enclosed in parentheses at the end of the procedure call. When the procedure is called, the extra data is given, or passed, to it. For example, in the statement Call GiveClue (intsecretnumber, intguess) the GiveClue procedure is called and two values are passed to it intsecretnumber and intguess. A variable or a value that is passed to a procedure is called an argument. In our example above, intsecretnumber and intguess are arguments that will be used by the procedure. A procedure that requires arguments is declared with parameters. The following syntax is used for a procedure with parameters: Sub ProcedureName(ByVal parameter1 As Type, ) statements Where: ProcedureName is the name of the procedure. ByVal indicates that the parameter is a value parameter. parameter1 is the name of the parameter. As Type is the data type of the parameter....statements is the body of the procedure. It is possible to have multiple parameters. Each parameter must be separated by a comma. ByVal and ByRef: ByVal indicates that the parameter is a value parameter. This means that the parameter's value is the only thing passed. ByRef indicates that the parameter is a reference parameter. This means that the reference to a variable would be passed as the parameter. Therefore, changes could be made to the variable s value which is not the case with ByVal. Parameters and Passing Arguments by Value (Continued) Once again, let's look at the GiveClue procedure: Sub GiveClue(ByVal intfirstnum As Integer, ByVal intsecondnum As Integer) If intfirstnum > intsecondnum Then MsgBox "Too low" Else MsgBox "Too high" End If When the GiveClue procedure is called with this statement: Call GiveClue (intsecretnumber, intguess) The value of the first argument, intsecretnumber, is assigned to the first parameter, intfirstnum. The value of the second argument, intguess, is assigned to the second parameter, intsecondnum. The image shows the two arguments in the Call statement being passed to the parameters declared in the GiveClue procedure. When a procedure is called, the number of arguments passed to it must match the number of parameters that have been declared. It is important to remember the following points: The order in which arguments are passed is important, as: The order of the arguments must correspond to the order of the parameters. For example, the first argument in the procedure call (intsecretnumber) corresponds to the first parameter(intfirstnum) and so on. Arguments passed by value can be in the form of a constant, a variable, values or expressions.

4 For example, the GiveClue Call statement could look like any of these: Call GiveClue(intSecretNumber, intguess) Call GiveClue(2*5, 10*2) Call GiveClue(10, intguess) Call GiveClue(10,20) Variable arguments that are passed by value are not changed by the procedure. For example, examine each line of code and its corresponding comment in green type: Sub Demo( ) Dim intcounter As Integer 'declares variable intcounter intcounter = 1 'assigns value of 1 to intcounter Call ShowCount(intCounter) 'call ShowCount procedure and passes_ copy of intcounter value(1) as argument to ShowCount procedure lblnumber.caption = intcounter 'Demo procedure displays value of_ intcounter(1) in the label. Value of intcounter(1) is_ unaffected by the ShowCount procedure Sub ShowCount(ByVal intcounter As Integer) 'parameter intcount_ receives value of 1 passed to it intcounter = intcounter + 1 'ShowCount procedure increments its_ intcounter variable by one to make value of intcounter 2 MsgBox intcounter 'ShowCount procedure displays value of_ intcounter(2) in the message box Static Variables Recall from Module 12 that variables may be local or global. Also, we saw that the scope of a variable refers to its accessibility to various procedures. A local variable is only available to the procedure in which it is declared, while a global variable is available to every procedure in the program module. In addition to scope, variables also have a lifetime in which they exist in memory. The lifetime of a local variable begins when the procedure is declared and ends when the procedure finishes execution. In other words, the local variable exists in memory while the procedure is executing. The end of the procedure signifies the end of the local variable's lifetime in memory. On the other hand, a global variable exists in memory for the duration of the program regardless of whether a procedure is executing or not. When the program is terminated, the global variable's lifetime is terminated. Variables may also be declared as static. When a variable is declared as static, the variable's: Scope is local to the procedure in which it is declared Lifetime is the duration of the program A static variable is declared using the Visual Basic keyword Static instead of the keyword Dim. It is good programming style to use static variables rather than global variables because the use of static variables does not interfere with other procedures. In the next exercise, we will write a program to add numbers. The program will use a static variable to maintain a running total. 1. Start the Visual Basic IDE. 2. Create a new project. 3. Design the interface as shown on the right: 4. Set the properties as shown in the table below: Object Name Caption Text Form1 frmaddingmachine Adding Machine! Label1 lbldirections Number to be added to the total is Text1 txtnewnum empty Label2 lblnumbersadded empty Label3 lbltotal empty Command1 cmdadd Click to Add Command2 cmddone Done

5 Once you have set the properties: 5. Save the project. Save the form as frmaddingmachine. Save the project as Adding Machine. 6. Double-click the Click to Add command button to display the Code window. Add the following code to the cmdadd_click procedure: Private Sub cmdadd_click() Dim dblnumberentered As Double Static dbltotal As Double 'declares static variable dblnumberentered = txtnewnum.text dbltotal = dbltotal + dblnumberentered 'keeps running total lblnumbersadded.caption = lblnumbersadded & " " _ & dblnumberentered & "+" lbltotal.caption = "Total = " & dbltotal Private Sub cmddone_click() Unload Me Resave your project. Run the application. Test the application by entering numbers and clicking the Click to Add button. Function Procedures A function, sometimes called a function procedure, performs a specific task and returns a value. Functions may be: Built-in User-defined We have already looked at several Visual Basic built-in functions in previous lessons, such as the built-in functions called Int, Lcase and Len. Functions may also be user-defined. User-defined functions use the following syntax: A function usually has at least one parameter. This parameter is for data that is required for the function to be able to perform its task. Parameters are ByVal because a function performs a task and returns a single value. The function should not change the arguments that it has been passed. Functions are useful for verifying user input. For example, an application that asks the user to enter a value between one and ten could use a user-defined Boolean function to determine if the user input falls within the correct range. The following is the code for a user-defined function called ValidEntry. This function will be used to check that the values entered by the user are within a predetermined range. The function parameters set the lower limit of the range to one and the upper limit of the range to ten.

6 Function ValidEntry(ByVal intusernum As Integer, ByVal intupperlimit As Integer, _ ByVal intlowerlimit As Integer)As Boolean If intusernum > intupperlimit Or intusernum < intlowerlimit Then ValidEntry = False Else ValidEntry = True End If End Function This code uses the ValidEntry function to check the user input: intguess = txtuserguess.text If Not ValidEntry(intGuess, 10,1) Then MsgBox "Invalid Guess. Please try again." End If The Boolean value that is returned by the ValidEntry function is then used as the condition for the If Then statement in the ValidEntry function. When working with functions, remember: The order of the arguments must match the order of the parameters. Only ByVal parameters should be declared in a function. A function should not change the arguments that are passed. A function returns a single value. This value will be used in another statement such as an assignment statement. For example, in the code shown in the preceding lesson, the Boolean value that is returned becomes the condition of the If Then statement.

NOTES: Variables & Constants (module 10)

NOTES: Variables & Constants (module 10) Computer Science 110 NAME: NOTES: Variables & Constants (module 10) Introduction to Variables A variable is like a container. Like any other container, its purpose is to temporarily hold or store something.

More information

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) Technology & Information Management Instructor: Michael Kremer, Ph.D. Database Program: Microsoft Access Series DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) AGENDA 3. Executing VBA

More information

NOTES: String Functions (module 12)

NOTES: String Functions (module 12) Computer Science 110 NAME: NOTES: String Functions (module 12) String Functions In the previous module, we had our first look at the String data type. We looked at declaring and initializing strings, how

More information

Before We Begin. Introduction to Computer Use II. Overview (1): Winter 2006 (Section M) CSE 1530 Winter Bill Kapralos.

Before We Begin. Introduction to Computer Use II. Overview (1): Winter 2006 (Section M) CSE 1530 Winter Bill Kapralos. Winter 2006 (Section M) Topic E: Subprograms Functions and Procedures Wednesday, March 8 2006 CSE 1530, Winter 2006, Overview (1): Before We Begin Some administrative details Some questions to consider

More information

Language Fundamentals

Language Fundamentals Language Fundamentals VBA Concepts Sept. 2013 CEE 3804 Faculty Language Fundamentals 1. Statements 2. Data Types 3. Variables and Constants 4. Functions 5. Subroutines Data Types 1. Numeric Integer Long

More information

Function: function procedures and sub procedures share the same characteristics, with

Function: function procedures and sub procedures share the same characteristics, with Function: function procedures and sub procedures share the same characteristics, with one important difference- function procedures return a value (e.g., give a value back) to the caller, whereas sub procedures

More information

Chapter 3. More Flow of Control. Copyright 2008 Pearson Addison-Wesley. All rights reserved.

Chapter 3. More Flow of Control. Copyright 2008 Pearson Addison-Wesley. All rights reserved. Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

More information

Please answer questions in the space provided. Question point values are shown in parentheses.

Please answer questions in the space provided. Question point values are shown in parentheses. IS 320 Spring 99 Page 1 Please answer questions in the space provided. Question point values are shown in parentheses. 1. (15) Assume you have the following variable declarations and assignments: Dim A

More information

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

More information

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines

More information

Microsoft Visual Basic 2005: Reloaded

Microsoft Visual Basic 2005: Reloaded Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations Objectives After studying this chapter, you should be able to: Declare variables and named

More information

VISUAL BASIC 6.0 OVERVIEW

VISUAL BASIC 6.0 OVERVIEW VISUAL BASIC 6.0 OVERVIEW GENERAL CONCEPTS Visual Basic is a visual programming language. You create forms and controls by drawing on the screen rather than by coding as in traditional languages. Visual

More information

20. VB Programming Fundamentals Variables and Procedures

20. VB Programming Fundamentals Variables and Procedures 20. VB Programming Fundamentals Variables and Procedures 20.1 Variables and Constants VB, like other programming languages, uses variables for storing values. Variables have a name and a data type. Array

More information

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132)

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132) BoredGames Language Reference Manual A Language for Board Games Brandon Kessler (bpk2107) and Kristen Wise (kew2132) 1 Table of Contents 1. Introduction... 4 2. Lexical Conventions... 4 2.A Comments...

More information

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18 Assignment Lecture 9 Logical Operations Formatted Print Printf Increment and decrement Read through 3.9, 3.10 Read 4.1. 4.2, 4.3 Go through checkpoint exercise 4.1 Logical Operations - Motivation Logical

More information

COP 2000 Introduction to Computer Programming Mid-Term Exam Review

COP 2000 Introduction to Computer Programming Mid-Term Exam Review he exam format will be different from the online quizzes. It will be written on the test paper with questions similar to those shown on the following pages. he exam will be closed book, but students can

More information

Part 4 - Procedures and Functions

Part 4 - Procedures and Functions Part 4 - Procedures and Functions Problem Solving Methodology... 2 Top Down Design... 2 Procedures and Functions... 5 Sub Procedures... 6 Sending Parameters to a Sub Procedure... 7 Pass by Value... 8 Pass

More information

Chapter Overview. More Flow of Control. Flow Of Control. Using Boolean Expressions. Using Boolean Expressions. Evaluating Boolean Expressions

Chapter Overview. More Flow of Control. Flow Of Control. Using Boolean Expressions. Using Boolean Expressions. Evaluating Boolean Expressions Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Copyright 2011 Pearson Addison-Wesley. All rights reserved.

More information

Programming Language 2 (PL2)

Programming Language 2 (PL2) Programming Language 2 (PL2) 337.1.1 - Explain rules for constructing various variable types of language 337.1.2 Identify the use of arithmetical and logical operators 337.1.3 Explain the rules of language

More information

Procedures in Visual Basic

Procedures in Visual Basic Procedures in Visual Basic https://msdn.microsoft.com/en-us/library/y6yz79c3(d=printer).aspx 1 of 3 02.09.2016 18:50 Procedures in Visual Basic Visual Studio 2015 A procedure is a block of Visual Basic

More information

Microsoft Visual Basic 2015: Reloaded

Microsoft Visual Basic 2015: Reloaded Microsoft Visual Basic 2015: Reloaded Sixth Edition Chapter Three Memory Locations and Calculations Objectives After studying this chapter, you should be able to: Declare variables and named constants

More information

Tech-Talk Using the PATROL Agent COM Server August 1999 Authored By: Eric Anderson

Tech-Talk Using the PATROL Agent COM Server August 1999 Authored By: Eric Anderson Tech-Talk Using the PATROL Agent COM Server August 1999 Authored By: Eric Anderson Introduction Among the many new features of PATROL version 3.3, is support for Microsoft s Component Object Model (COM).

More information

Level 3 Computing Year 2 Lecturer: Phil Smith

Level 3 Computing Year 2 Lecturer: Phil Smith Level 3 Computing Year 2 Lecturer: Phil Smith Previously We started to build a GUI program using visual studio 2010 and vb.net. We have a form designed. We have started to write the code to provided the

More information

DroidBasic Syntax Contents

DroidBasic Syntax Contents DroidBasic Syntax Contents DroidBasic Syntax...1 First Edition...3 Conventions Used In This Book / Way Of Writing...3 DroidBasic-Syntax...3 Variable...4 Declaration...4 Dim...4 Public...4 Private...4 Static...4

More information

Chapter 2.4: Common facilities of procedural languages

Chapter 2.4: Common facilities of procedural languages Chapter 2.4: Common facilities of procedural languages 2.4 (a) Understand and use assignment statements. Assignment An assignment is an instruction in a program that places a value into a specified variable.

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Good Variable Names: dimensionone, dimension1 Bad Variable Names: dimension One, 1dimension

Good Variable Names: dimensionone, dimension1 Bad Variable Names: dimension One, 1dimension VB Scripting for CATIA V5: Email Course by Emmett Ross Lesson #4 - CATIA Macro Variable Naming Variables make up the backbone of any programming language. Basically, variables store information that can

More information

CHAD Language Reference Manual

CHAD Language Reference Manual CHAD Language Reference Manual INTRODUCTION The CHAD programming language is a limited purpose programming language designed to allow teachers and students to quickly code algorithms involving arrays,

More information

Python Games. Session 1 By Declan Fox

Python Games. Session 1 By Declan Fox Python Games Session 1 By Declan Fox Rules General Information Wi-Fi Name: CoderDojo Password: coderdojowireless Website: http://cdathenry.wordpress.com/ Plans for this year Command line interface at first

More information

CHIL CSS HTML Integrated Language

CHIL CSS HTML Integrated Language CHIL CSS HTML Integrated Language Programming Languages and Translators Fall 2013 Authors: Gil Chen Zion gc2466 Ami Kumar ak3284 Annania Melaku amm2324 Isaac White iaw2105 Professor: Prof. Stephen A. Edwards

More information

Complete program to solve a 2 nd degree equation

Complete program to solve a 2 nd degree equation Fundamentals of Computer Science 2010-2011 Laboratory 10 Functions and procedures (3) Objectives: To go deeply into the use of subprograms and passing parameters by reference To go deeply into the manipulation

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

More information

Variable A variable is a value that can change during the execution of a program.

Variable A variable is a value that can change during the execution of a program. Declare and use variables and constants Variable A variable is a value that can change during the execution of a program. Constant A constant is a value that is set when the program initializes and does

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 2

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 2 Jim Lambers ENERGY 211 / CME 211 Autumn Quarter 2007-08 Programming Project 2 This project is due at 11:59pm on Friday, October 17. 1 Introduction In this project, you will implement functions in order

More information

Introduction to Data Entry and Data Types

Introduction to Data Entry and Data Types 212 Chapter 4 Variables and Arithmetic Operations STEP 1 With the Toolbox visible (see Figure 4-21), click the Toolbox Close button. The Toolbox closes and the work area expands in size.to reshow the Toolbox

More information

IS 320 Spring 96 Page 1 Exam 1. Please use your own paper to answer the following questions. Point values are shown in parentheses.

IS 320 Spring 96 Page 1 Exam 1. Please use your own paper to answer the following questions. Point values are shown in parentheses. IS 320 Spring 96 Page 1 Please use your own paper to answer the following questions. Point values are shown in parentheses. 1. (10) Consider the following segment of code: If txtansicode.text < "0" Or

More information

variables programming statements

variables programming statements 1 VB PROGRAMMERS GUIDE LESSON 1 File: VbGuideL1.doc Date Started: May 24, 2002 Last Update: Dec 27, 2002 ISBN: 0-9730824-9-6 Version: 0.0 INTRODUCTION TO VB PROGRAMMING VB stands for Visual Basic. Visual

More information

Unit 4. Lesson 4.1. Managing Data. Data types. Introduction. Data type. Visual Basic 2008 Data types

Unit 4. Lesson 4.1. Managing Data. Data types. Introduction. Data type. Visual Basic 2008 Data types Managing Data Unit 4 Managing Data Introduction Lesson 4.1 Data types We come across many types of information and data in our daily life. For example, we need to handle data such as name, address, money,

More information

Chapter 3. More Flow of Control

Chapter 3. More Flow of Control Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-2 Flow Of Control Flow of control refers to the

More information

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode STUDENT OUTLINE Lesson 8: Structured Programming, Control Structures, if- Statements, Pseudocode INTRODUCTION: This lesson is the first of four covering the standard control structures of a high-level

More information

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003 Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an

More information

Sub Programs. To Solve a Problem, First Make It Simpler

Sub Programs. To Solve a Problem, First Make It Simpler Sub Programs To Solve a Problem, First Make It Simpler Top Down Design Top Down Design Start with overall goal. Break Goal into Sub Goals Break Sub Goals into Sub Sub Goals Until the Sub-Sub Sub-Sub Sub-Sub

More information

Software Design & Programming I

Software Design & Programming I Software Design & Programming I Starting Out with C++ (From Control Structures through Objects) 7th Edition Written by: Tony Gaddis Pearson - Addison Wesley ISBN: 13-978-0-132-57625-3 Chapter 4 Making

More information

SKILL AREA 306: DEVELOP AND IMPLEMENT COMPUTER PROGRAMS

SKILL AREA 306: DEVELOP AND IMPLEMENT COMPUTER PROGRAMS Add your company slogan SKILL AREA 306: DEVELOP AND IMPLEMENT COMPUTER PROGRAMS Computer Programming (YPG) LOGO 306.1 Review Selected Programming Environment 306.1.1 Explain the concept of reserve words,

More information

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

More information

VBSCRIPT - INTERVIEW QUESTIONS

VBSCRIPT - INTERVIEW QUESTIONS VBSCRIPT - INTERVIEW QUESTIONS http://www.tutorialspoint.com/vbscript/vbscript_interview_questions.htm Copyright tutorialspoint.com Dear readers, these VBScript Interview Questions have been designed specially

More information

Sprite an animation manipulation language Language Reference Manual

Sprite an animation manipulation language Language Reference Manual Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3

More information

VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals

VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals VARIABLES WHAT IS A VARIABLE? A variable is a storage location in the computer s memory, used for holding information while the program is running. The information that is stored in a variable may change,

More information

YOLOP Language Reference Manual

YOLOP Language Reference Manual YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language

More information

CSC 112 :: Test #2 Study Guide with Answers April 25, 2012 Short Answer Questions

CSC 112 :: Test #2 Study Guide with Answers April 25, 2012 Short Answer Questions CSC 112 :: Test #2 Study Guide with Answers April 25, 2012 Short Answer Questions (1-6) Regarding the code for Lab #7: Private Const NUMLABELS As Integer = 5 Private lblelement(numlabels) As Label ' Array

More information

Copyright (c) by Matthew S. Harris

Copyright (c) by Matthew S. Harris Documentation & How-To Didjiman's Forms Instance Manager Class For MS Access 2007 and Higher Version v2017-03-28 Copyright (c) 2014-2017 by Matthew S. Harris Permission is granted to copy, distribute and/or

More information

Teaching London Computing

Teaching London Computing Teaching London Computing A Level Computer Science Topic 3: Advanced Programming in Python William Marsh School of Electronic Engineering and Computer Science Queen Mary University of London Aims Further

More information

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto CS 170 Java Programming 1 The Switch Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Menu-Style Code With ladder-style if-else else-if, you might sometimes find yourself writing menu-style

More information

Unit 2: Java in the small. Prepared by: Dr. Abdallah Mohamed, AOU-KW

Unit 2: Java in the small. Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit 2: Java in the small Prepared by: Dr. Abdallah Mohamed, AOU-KW 1 Unit 2: Java in the small Introduction The previous unit introduced the idea of objects communicating through the invocation of methods

More information

Cellular Automata Language (CAL) Language Reference Manual

Cellular Automata Language (CAL) Language Reference Manual Cellular Automata Language (CAL) Language Reference Manual Calvin Hu, Nathan Keane, Eugene Kim {ch2880, nak2126, esk2152@columbia.edu Columbia University COMS 4115: Programming Languages and Translators

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #17. Loops: Break Statement

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #17. Loops: Break Statement Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #17 Loops: Break Statement (Refer Slide Time: 00:07) In this session we will see one more feature that is present

More information

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below: QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Unit 3. Operators. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

More information

Slide 1 CS 170 Java Programming 1 The while Loop Duration: 00:00:60 Advance mode: Auto

Slide 1 CS 170 Java Programming 1 The while Loop Duration: 00:00:60 Advance mode: Auto CS 170 Java Programming 1 The while Loop Writing Counted Loops and Loops that Check a Condition Slide 1 CS 170 Java Programming 1 The while Loop Duration: 00:00:60 Hi Folks. Welcome to the CS 170, Java

More information

Microsoft Office Excel Use Excel s functions. Tutorial 2 Working With Formulas and Functions

Microsoft Office Excel Use Excel s functions. Tutorial 2 Working With Formulas and Functions Microsoft Office Excel 2003 Tutorial 2 Working With Formulas and Functions 1 Use Excel s functions You can easily calculate the sum of a large number of cells by using a function. A function is a predefined,

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

CSC Web Programming. Introduction to JavaScript

CSC Web Programming. Introduction to JavaScript CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its

More information

Flow Control. CSC215 Lecture

Flow Control. CSC215 Lecture Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements

More information

Programming Lecture 4

Programming Lecture 4 Five-Minute Review 1. What are classes and objects? What is a class hierarchy? 2. What is an expression? A term? 3. What is a variable declaration? 4. What is an assignment? What is precedence? 5. What

More information

Lecture 19 CSE August You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii.

Lecture 19 CSE August You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii. Lecture 19 CSE 110 5 August 1992 You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii. 1 Left-Over Language Features Today was the day we saw the last

More information

(Subroutines in Visual Basic)

(Subroutines in Visual Basic) Ch 7 Procedures (Subroutines in Visual Basic) Visual Basic Procedures Structured Programs To simplify writing complex programs, most Programmers (Designers/Developers) choose to split the problem into

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

Looping Subtasks. We will examine some basic algorithms that use the while and if constructs. These subtasks include

Looping Subtasks. We will examine some basic algorithms that use the while and if constructs. These subtasks include 1 Programming in C Looping Subtasks We will examine some basic algorithms that use the while and if constructs. These subtasks include Reading unknown quantity of data Counting things Accumulating (summing)

More information

ADMIN STUFF. Assignment #1 due. Assignment #2. Midterm. Posted to website Due Oct 11. Review session Oct 16 Midterm in class Oct 18 [2 hours long]

ADMIN STUFF. Assignment #1 due. Assignment #2. Midterm. Posted to website Due Oct 11. Review session Oct 16 Midterm in class Oct 18 [2 hours long] TODAY S QUOTE Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are by definition not smart enough to debug it. (Brian Kernighan)

More information

Excel VBA Variables, Data Types & Constant

Excel VBA Variables, Data Types & Constant Excel VBA Variables, Data Types & Constant Variables are used in almost all computer program and VBA is no different. It's a good practice to declare a variable at the beginning of the procedure. It is

More information

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage: Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;

More information

Java+- Language Reference Manual

Java+- Language Reference Manual Fall 2016 COMS4115 Programming Languages & Translators Java+- Language Reference Manual Authors Ashley Daguanno (ad3079) - Manager Anna Wen (aw2802) - Tester Tin Nilar Hlaing (th2520) - Systems Architect

More information

Unit 2: Java in the small

Unit 2: Java in the small Prepared by: Dr. Abdallah Mohamed, AOU-KW 1 Introduction The previous unit introduced the idea of objects communicating through the invocation of methods on objects. In this unit you will learn: how to

More information

In this lab, you will learn more about selection statements. You will get familiar to

In this lab, you will learn more about selection statements. You will get familiar to Objective: In this lab, you will learn more about selection statements. You will get familiar to nested if and switch statements. Nested if Statements: When you use if or if...else statement, you can write

More information

2.8. Decision Making: Equality and Relational Operators

2.8. Decision Making: Equality and Relational Operators Page 1 of 6 [Page 56] 2.8. Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. This section introduces a simple version of Java's if statement

More information

GOLD Language Reference Manual

GOLD Language Reference Manual GOLD Language Reference Manual Language Guru: Timothy E. Chung (tec2123) System Architect: Aidan Rivera (ar3441) Manager: Zeke Reyna (eer2138) Tester: Dennis Guzman (drg2156) October 16th, 2017 1 Introduction

More information

15 FUNCTIONS IN C 15.1 INTRODUCTION

15 FUNCTIONS IN C 15.1 INTRODUCTION 15 FUNCTIONS IN C 15.1 INTRODUCTION In the earlier lessons we have already seen that C supports the use of library functions, which are used to carry out a number of commonly used operations or calculations.

More information

Connecting with Computer Science, 2e. Chapter 15 Programming II

Connecting with Computer Science, 2e. Chapter 15 Programming II Connecting with Computer Science, 2e Chapter 15 Programming II Objectives In this chapter you will: Gain an understanding of the basics of high-level programming languages, using Java and C++ as examples

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Higher Computing Science Software Design and Development - Programming Summary Notes

Higher Computing Science Software Design and Development - Programming Summary Notes Higher Computing Science Software Design and Development - Programming Summary Notes Design notations A design notation is the method we use to write down our program design. Pseudocode is written using

More information

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Lesson 06 Arrays MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Array An array is a group of variables (called elements or components) containing

More information

A variable is a name that represents a value. For

A variable is a name that represents a value. For DECLARE A VARIABLE A variable is a name that represents a value. For example, you could have the variable myage represent the value 29. Variables can be used to perform many types of calculations. Before

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Methods. Contents Anatomy of a Method How to design a Method Static methods Additional Reading. Anatomy of a Method

Methods. Contents Anatomy of a Method How to design a Method Static methods Additional Reading. Anatomy of a Method Methods Objectives: 1. create a method with arguments 2. create a method with return value 3. use method arguments 4. use the return keyword 5. use the static keyword 6. write and invoke static methods

More information

Statements and Operators

Statements and Operators Statements and Operators Old Content - visit altium.com/documentation Mod ifi ed by Rob Eva ns on Feb 15, 201 7 Parent page: EnableBasic Enable Basic Statements Do...Loop Conditional statement that repeats

More information

CS112 Lecture: Repetition Statements

CS112 Lecture: Repetition Statements CS112 Lecture: Repetition Statements Objectives: Last revised 2/18/05 1. To explain the general form of the java while loop 2. To introduce and motivate the java do.. while loop 3. To explain the general

More information

The name of this type library is LabelManager2 with the TK Labeling Interface reference.

The name of this type library is LabelManager2 with the TK Labeling Interface reference. Page 1 of 10 What is an ActiveX object? ActiveX objects support the COM (Component Object Model) - Microsoft technology. An ActiveX component is an application or library that is able to create one or

More information

APCS Semester #1 Final Exam Practice Problems

APCS Semester #1 Final Exam Practice Problems Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester

More information

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like? Chapter 3 - Simple JavaScript - Programming Basics Lesson 1 - JavaScript: What is it and what does it look like? PP presentation JavaScript.ppt. Lab 3.1. Lesson 2 - JavaScript Comments, document.write(),

More information

d2vbaref.doc Page 1 of 22 05/11/02 14:21

d2vbaref.doc Page 1 of 22 05/11/02 14:21 Database Design 2 1. VBA or Macros?... 2 1.1 Advantages of VBA:... 2 1.2 When to use macros... 3 1.3 From here...... 3 2. A simple event procedure... 4 2.1 The code explained... 4 2.2 How does the error

More information

Sébastien Mathier wwwexcel-pratiquecom/en Variables : Variables make it possible to store all sorts of information Here's the first example : 'Display the value of the variable in a dialog box 'Declaring

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

egrapher Language Reference Manual

egrapher Language Reference Manual egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments Basics Objectives Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments 2 Class Keyword class used to define new type specify

More information

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs. Java SE11 Development Java is the most widely-used development language in the world today. It allows programmers to create objects that can interact with other objects to solve a problem. Explore Java

More information

ADVANTAGES. Via PL/SQL, all sorts of calculations can be done quickly and efficiently without use of Oracle engine.

ADVANTAGES. Via PL/SQL, all sorts of calculations can be done quickly and efficiently without use of Oracle engine. 1 PL/SQL INTRODUCTION SQL does not have procedural capabilities. SQL does not provide the programming techniques of condition checking, looping and branching that is required for data before permanent

More information

Computer Programming I - Unit 5 Lecture page 1 of 14

Computer Programming I - Unit 5 Lecture page 1 of 14 page 1 of 14 I. The while Statement while, for, do Loops Note: Loop - a control structure that causes a sequence of statement(s) to be executed repeatedly. The while statement is one of three looping statements

More information