Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic.

Similar presentations


Presentation on theme: "Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic."— Presentation transcript:

1 Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 8 Languages and Environments

2 Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School 2009 2 Modularity You refine a complex program by progressively breaking it down into smaller, easier-to solve units (top-down design with step-wise refinement). Each of these units, called modules, can be independently coded in a high level language and then amalgamated to form the complete program. The use of structure charts emphasize this modular design and also the relationship between all the modules in the software system. The programs that you will be writing in Visual Basic will be relatively short and you might not see the need to use modular techniques. Visual Basic is an events-driven programming language, programming is done in a graphical environment. Users can click on various objects where each object is programmed independently to be able to respond to user actions. A Visual Basic program is, therefore modular being made up of many subprograms, each having its own program code that can be executed independently. These subprograms are called procedures and functions.

3 Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School 2009 3 Modularity Procedures and functions provide a means of producing structured programs. The more complex a program becomes the more reason to employ strategies to make it easier to read and maintain. Procedures and functions help by breaking the extensive lines of code into small, meaningful sections. As a consequence: repetition of lines of code is avoided - code is placed in a procedure or function. The procedure is then called as many times as necessary without re-writing the code; it allows testing of the procedure code to take place in isolation from the main program. debugging main body of the program is simplified as each procedure is individually tested; procedure code can be saved and re-used in future projects. Eg Module libraries -repositories for useful modules that are pre-tested and documented.

4 Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School 2009 4 Procedures and Functions Procedures and functions allow strategies to be employed to make it easier to read and maintain code. Procedures and functions break up what would be extensive lines of intricate code into more meaningful and logical sections. As a consequence: the repetition of lines of code are avoided by placing code in a procedure or function. Call the procedure or function as often as necessary. it allows testing of each procedure individually. debugging of entire code is simplified since each procedure has been individually tested procedure code can be saved and re-used in Module libraries. A procedure or function is activated by a call from the main program, after which the procedure or function executes its block of code and then terminates. The flow of data between procedures, functions and the main program block is accomplished by the use of parameters, which will be discussed later.

5 Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School 2009 5 Procedures and Functions Procedures Visual Basic offers a variety of procedure types. The two that concern us here are: Up to now most of all the programming code you have seen has been made up of event procedures that activate sections of code when, say a command button is pressed. These procedures are named by Visual Basic by concatenating the name of the object code and the name of the event according to the syntax: Sub Command_Click() End End Sub You will recognise this code which ends a Visual Basic program. event procedures general procedures.

6 Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School 2009 6 Procedures and Functions General Procedures A general procedure, unlike an event procedure is user-defined with its block of code being called from the main program. The basic structure for a procedure is Sub procedure_name (formal parameters) Declarations Statements End Sub The name, procedure_name or identifier, is what is used when the procedure is called and the name conforms to the same rules of naming variables. Data is passed to and from the main program using the procedure parameters. Not all procedures however need to have parameters. The declarations and statements follow an identical pattern to normal programming constructs. Procedures are normally declared private and their scope is limited to other procedures and variables within the current form.

7 Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School 2009 7 Procedures and Functions Parameter passing Parameter passing is the main mechanism for transferring information between programs and sub procedures in Visual Basic. Parameters can be classified into various types, depending on how they deal with data values during a procedure call. Other than using global variables, parameter passing using local variables is the way in which information is transmitted to and/or from called procedures in a program. The formal parameters can behave in one of three ways: 1.They can pass information to a sub program 2.They can receive information from a sub program 3.They can both send and receive information. These three methods are described as: 1.IN mode or use of an IN parameter 2.OUT mode or use of an OUT parameter 3.IN/OUT mode or use of an IN/OUT parameter.


Download ppt "Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic."

Similar presentations


Ads by Google