National Diploma Unit 4 Introduction to Software Development Procedures and Functions.

Slides:



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

Working with Intrinsic Controls and ActiveX Controls
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Lecture 2 Introduction to C Programming
Writing General Procedures Often you will encounter programming situations in which multiple procedures perform the same operation This condition can occur.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
VBA Modules, Functions, Variables, and Constants
Example 2.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Using the Visual Basic Editor Visual Basic for Applications 1.
Introduction to a Programming Environment
Scope of Variables and Constants A Variable or Constant may exist and be Visible for an entire project, for only one form, or for only one procedure Therefore,
Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.
Software design and development Marcus Hunt. Application and limits of procedural programming Procedural programming is a powerful language, typically.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: String Manipulation
Apply Sub Procedures/Methods and User Defined Functions
CS0004: Introduction to Programming Variables – Numbers.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
IE 212: Computational Methods for Industrial Engineering
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Automating Tasks with Visual Basic. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Why to Create a Procedure
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
110-G1 Motivation: Within a program, may have to perform the same computation over and over Many programs share the same computation (e.g. sorting) To.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
I Power Higher Computing Software Development Development Languages and Environments.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
I Power Higher Computing Software Development High Level Language Constructs.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Debugging, Static Variables, ByRef, ByValue Chapt. 6 in Deitel, Deitel and Nieto.
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
1 Writing Software Kashef Mughal. 2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm.
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.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
BACS 287 Programming Fundamentals 5. BACS 287 Programming Fundamentals This lecture introduces the following topics: – Procedures Built-in Functions User-defined.
Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
More on Variables and Subroutines. Introduction Discussion so far has dealt with self- contained subs. Subs can call other subs or functions. A module.
Chapter 15: Sub Procedures and Function Procedures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
Copyright © 2014 Pearson Education, Inc. Chapter 6 Procedures and Functions.
Subroutines and Functions Chapter 6. Introduction So far, all of the code you have written has been inside a single procedure. –Fine for small programs,
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
Visual Basic I Programming
A variable is a name for a value stored in memory.
Spreadsheet-Based Decision Support Systems
Using Procedures and Exception Handling
VISUAL BASIC.
Procedures and Functions
CS285 Introduction - Visual Basic
Chapter 7: Using Functions, Subs, and Modules
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Chapter 8 - Functions and Functionality
STARTING OUT WITH Visual Basic 2008
10.3 Procedures Function Procedures 07/06/2019.
Presentation transcript:

National Diploma Unit 4 Introduction to Software Development Procedures and Functions

Procedural programming These programs are executed line by line in a stepwise fashion Commands are interpreted line by line or the whole program is compiled first Complex programs might be broken down into a series of sub procedures In event driven programming (like VB), sub procedures usually run in response to an event such as a mouse clicking a button

Problem What if I want the same piece of code to run when a user clicks several controls? I could write the code behind each control by copying and pasting it This is not good practice – the more code you write, the more has to be stored, the more resources this uses up Better to write one general procedure that can be used many times

General procedures Are written in the general area of the form So far we have only used this to declare variables available to the whole form and to use the option explicit statement to make sure that all variables have to be declared before use

Creating a general procedure Click on the Tools menu item and then select Add Procedure

Creating a general procedure Select Sub, give the procedure a name. Note that the default scope is Public - this can be accessed throughout the program Your procedure will appear in the General area of the form.

Complex programs It might be that a really big program consists of many forms In this case, you want the procedure to be visible everywhere The best move is to create a Module to hold all of your general code that is not associated with a particular form or any controls on that form

Creating a module Select the Add Module option from the Project menu item. A module appears as a new project item and you can view all of the code but remember that there isn’t a form or any controls associated with a module.

Why use modules? The really great thing about modules is that if they are general purpose ones, they can be imported and reused in any other VB project This is good programming practice – modular code that permits reuse

Functions A Function is still a procedure but a special one – it returns a value to the procedure that called it. Adding a function is similar to adding a general procedure but select the function option

Functions Very often, rather than the program just running a bit of code, we want it to do something to a value and then return that new value to the program You all know what Add does If I said “you have two numbers: 1 and 6. Now Add them……… This is how functions work and the function would return 7

Calling a function Since functions are either in the general area of a form or in a module, we have to Call them A function will expect something to be sent to it (numbers 1 and 6 in our previous example) These are the Arguments

Calling a function Here is the example function from the practical handout Here it is being called in code and the argument being passed to it

Passing values Any sub procedure or function could possibly change a variable value In the first example, two arguments were passed that had the values of 1 and 6 I would have declared these are intNumber1 and intNumber2

Passing values by reference The function, by default will have the actual values passed to it – this is passing by reference In our example, this is fine, I store the total in another slot in memory, intTotal If I didn’t, I could overwrite the original value which might be needed elsewhere in the program

Passing values by value This is a safer bet when it is vital that a variable value is not overwritten You need to add the ByVal keyword to the argument: Public function doubleIt (ByVal intNumber) doubleIt will now make a copy of the value of intNumber and use that in the calculation

Using built in functions VB has loads of useful built in functions that you can call by name in your code: Date – returns the date Time – returns the time InputBox – returns whatever the user entered in the textbox MsgBox – returns a value depending on which button the user pressed

Built in functions Int – returns the integer part of a number IsNumeric – tests whether a value is a number or not. Returns true or false. Now – returns current system date and time Len – returns the number of characters in a string Left$- returns the leftmost character in a string Mid$ - returns a part of a string Right$ - guess what this does?

Return to Main menu