Software Development
description
Transcript of Software Development
![Page 1: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/1.jpg)
1
Software Development
Int2/Higher
![Page 2: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/2.jpg)
2
Software
• What is software?– All programs that allow hardware to do
something useful and interesting
• You probably use several different pieces of software every day/week– Examples?
• What is hardware?– Everything that you can touch
![Page 3: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/3.jpg)
3
Software
• A piece of software is simply a list of instructions that are fed to the computer and executed
• It is therefore important that these instructions are in the correct order and the instructions themselves are correct
![Page 4: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/4.jpg)
4
Questions• What is the meaning of the term hardware?• Give three examples of software.• Complete the following table:
Item Hardware software
Monitor
Database
Windows XP
Scanner
An e-mail
Internet Explorer
Mouse
Modem
Computer game
Word processor
Digital camera
![Page 5: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/5.jpg)
5
The Development Process
• The software development cycle is a systematic approach to producing software. The software development life cycle can be summed up in the following stages:
Analysis Design Implementation Testing Documentation Evaluation Maintenance
![Page 6: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/6.jpg)
6
Development ProcessIt can be difficult to remember all of
these stages in order. This little mnemonic might help.Or, you might develop your own. A Dance In The Dark Every Monday
nalysis
ocumentat ion
mplementation
esting
esign
valuation
aintenance
![Page 7: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/7.jpg)
7
Software Development Process
• Analysis – To look at the problem and determine what the solution might be. Use existing systems or write a new program? Turn the rough idea into an exact description. What are the inputs and outputs? What type of computer will it be run on? All of these questions must be answered at this stage.
![Page 8: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/8.jpg)
8
Who does it?
• The systems analyst is the person who is responsible for the analysis stage
![Page 9: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/9.jpg)
9
Skills of the Systems Analyst
• Usually a skilled and experienced programmer
• Good people skills
• Good communication skills
![Page 10: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/10.jpg)
10
What do they do?
• Interview clients
• Observation notes – of existing practice
• Questionnaires
• All of these are categorised as requirements elicitation
![Page 11: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/11.jpg)
11
The Importance of Being Analytical
• The systems analyst has to be very detailed and accurate– So the rest of the process runs smoothly– Examples of what could go wrong?
– After requirements elicitation the analyst will create a requirements specification (program/problem specification) – contains a full problem description, inputs and outputs etc
![Page 12: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/12.jpg)
12
Put the following in the correct order
– 1. Create a user manual– 2. Get the team together to discuss what the
game’s purpose is and what kind of things the player will be able to do
– 3. Create the game– 4. Fix the problems found in testing. Produce
downloadable updates for the game– 5. Design the games characters and worlds.
Produce a plan for when certain parts of the game should be finished
– 6. Make sure the game works properly– 7. Allow some people to play the game and
ask them what they think of it
![Page 13: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/13.jpg)
13
Blob Diagram(analysis)
• Used to determine the inputs and outputs to a program, using tea example:
Making tea
Tea bag
water
milk
sugar
Used tea bag
Boiled water
Cup of tea
![Page 14: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/14.jpg)
14
Blob Diagram
• Create a blob diagram for the following program
• A program that asks the user the length and breadth of a floor in metres. It will also ask the user the price of the carpet they will use (in m2) and then tells the user how much carpet will be required and the total cost
• When you have done this, try to create the program in Visual Basic
![Page 15: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/15.jpg)
15
Blog Entry: The Software Development Lifecycle
• Higher– The 7 stages of the
SD Lifecycle– Analysis – What
happens here, who does it, how do they do it and what do they produce
– Techniques – what techniques are used
• Int2– The 7 stages of the
SD Lifecycle– Analysis: What
happens at this stage and what is produced
– Blob diagram
![Page 16: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/16.jpg)
16
Software Development Process
• Design – jumping straight into coding a program is not a good idea. This stage is important as the details of the program are worked out here. Things like how the screen will look, how the user will interact with the program and how the program might be structured. There are a variety of design methods. Pseudocode and structure diagrams are two of the most common.
![Page 17: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/17.jpg)
17
Pseudocode
Like an English version of the program but can have code in it too if the designer knows how they will code it
If done properly the pseudocode should match the program line for line
Take making a cup of tea as an example 1. Fill kettle2. Boil kettle3. When kettle boiled pour hot water in cup4. Add tea bag, milk and sugar5.Stir
We can then use this as the design for our program
![Page 18: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/18.jpg)
18
Your turn
• Write the Pseudocode for the following:
• A program that asks the user which times table they wish to be displayed. The program will then display that times table in a list box
![Page 19: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/19.jpg)
19
Structure Diagram
• Fairly simple, take the tea making example
Making tea
Fill kettle Boil kettle StirWhen kettle boiled pour into cup
Add milk, sugar
![Page 20: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/20.jpg)
20
Structure Diagram(with data flow)
• Indicates what variables are passed in and out of procedures
Area of rectangle
Get sizes Calculate area Display area
Find out length Find out breadth
Area = length x breadth
Length
breadth
Length
breadth areaarea
![Page 21: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/21.jpg)
21
Structure diagram
• Draw the following structure diagrams (with data flow)– A program that calculates the area of
people’s gardens when given the length and breadth in metres
– A program that works out the average test score for a pupil from 3 different test scores
![Page 22: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/22.jpg)
22
Software Development Process
• Implementation – This is the process of turning the design into a suitable programming language. We will use a High Level Language, called Visual Basic.
• Testing – A great deal of time is spent on testing. A wide range of conditions will be tested. Normal, extreme and exceptional testing.
![Page 23: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/23.jpg)
23
Documentation
• User Guide: Details of how to use the program
• Technical Guide: The minimum specifications required of the computer you wish to install the software on. Will also contain installation instructions
![Page 24: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/24.jpg)
24
Maintenance
• The 7th and last stage of the development process– Continuous
• 3 types of maintenance– Corrective– Perfective– Adaptive
![Page 25: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/25.jpg)
25
Maintenance• Corrective
– Fix bugs that appear when program is in use– Company might make downloadable “patch” available
• Perfective– Adding new features– Might mean a new a version of the software is
created
• Adaptive– When software needs to take account of some
change in the conditions it operates in• E.g. new version of operating system for example was
designed for Windows XP and adapted to run on Windows Vista
![Page 26: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/26.jpg)
26
Order these steps correctly
• A – writing a user guide and technical guide for the software
• B – Deciding the game you want to create, and what features you want it to have
• C – adapting the game to run on a different type of computer
• D – Actually writing the program code• E – Checking that the program does what it is
supposed to do, is easy to use, and can be fixed if there is a problem
• F – working out the details of what the screens will look like, what menus and functions there will be, and other detailed aspects of the program
• G – Getting users to try out the program to make sure it works under most conditions
![Page 27: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/27.jpg)
27
ANALYSIS – the user requirements are determined at this stage
DESIGN – Software and Program design are detailed at this stage
IMPLEMENTATION – actual program put into operation
TESTING – errors and bugs corrected
DOCUMENTATION – technical and user guide drawn up.
EVALUATION - refinements
MAINTENANCE-upgrading
SOFTWARE DEVELOPMEN
T
LIFECYCLE
Copy this diagram
![Page 28: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/28.jpg)
28
High Level Languages (HLLs)
• Just like human language, there are many different types of programming language
• Each has been designed to solve a specific type of problem
• Each has it’s own strengths and weaknesses
![Page 29: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/29.jpg)
29
High Level Languages (HLLs)
• Visual Basic is an example of a High Level Language
• High Level Languages contain ‘normal’ words and are close to English
• This makes them relatively easy for us to understand
• However, as we know computers only understand binary
![Page 30: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/30.jpg)
30
Low Level Languages
• Low level languages are closer to the language that the computer can understand
• It is very difficult to track down and fix bugs using these languages
![Page 31: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/31.jpg)
31
Machine Code
• Computers only understand binary, the only input a processor will accept is a binary code and it will only give this as output, these are known as Machine Codes
• There are a number of problems with Machine Codes– They are different from processor to processor– Hard for humans to understand and use– Difficult to find and fix errors
![Page 32: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/32.jpg)
32
Questions
• Which type of language (high or low) is easier to understand?
• Which type would be easier to correct if it had a mistake in it?
• Name 2 low level languages• Name 2 high level languages• Explain the main differences between high
and low level languages• List 2 advantages of high level languages
![Page 33: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/33.jpg)
33
High/Low Level Languages
• High– Visual Basic– Pascal– Logo– Java
• Low– Machine Code– Assembler
![Page 34: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/34.jpg)
34
How does a computer understand a HLL?
• The short answer is it doesn’t– What could we do if we wanted to
communicate with a Chinese person who doesn’t speak English and we don’t speak Chinese?
• Get a translator
• This is exactly what a computer does• Every HLL has a translator to
translate it to code the computer understands
![Page 35: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/35.jpg)
35
Translators
• There are 2 different types of translator– Compiler and Interpreter
• Each has strengths and weaknesses
![Page 36: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/36.jpg)
36
Interpreters
• Take each line one at a time and convert to machine code– This is the reason that Visual Basic tells
you when you’ve made a mistake at the end of each line
• This means when a program is run the line has to first be translated and then executed, which slows the program down
![Page 37: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/37.jpg)
37
Interpreters
• The program needs to be translated each time it is run so there is no way to speed the process up.
• This means the interpreter and the program must be stored after the program is complete
• Where the program goes the interpreter is needed
![Page 38: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/38.jpg)
38
Compiler
• Translates the program when it has been completed
• It takes the whole program and converts it to machine code at once
• This machine code can be kept and run as many times as you want
• Means the program runs faster• Only the compiled program needs to
be stored
![Page 39: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/39.jpg)
39
Questions
• Name the two main types of translator programs
• Which one translates the whole program into machine code before it is executed?
• Which translates the program line by line?• Why do machine code programs run more
quickly on a computer than high level language programs?
![Page 40: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/40.jpg)
40
Text Editors
• Implementation of a program takes place in a high level language(HLL)
• High level languages are very close to English and therefore we can use tools much like those we would use when typing an essay e.g. cut and paste
• HLLs can be typed in a word processing package and saved as a text file, ready for translation to machine code
![Page 41: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/41.jpg)
41
Scripting Language and Macros
• This unit is mostly concerned with the process of developing stand alone applications in high level languages
• However small programs can be developed within some existing application packages
• These are called macros– Macros are time saving programs written in a scripting
language which can be activated by a series of key strokes for repeated use. They will only work with an application program, they cannot exist alone.
• They can extend the functionality of an application
• They customise applications
![Page 42: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/42.jpg)
42
Questions
• What is a macro?
• What type of language is used to write macros?
• What are the advantages of using macros?
• Describe 2 examples where a macro could be useful.
![Page 43: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/43.jpg)
43
Variables(Implementation)
• We declare variables in our program to hold values that might change throughout the execution of our program
• We will be mainly using 3 variable types in this course. String (for text), Integer (whole numbers) and Single (numbers with fractions)
• If we declare a variable as a certain type the program will expect this type to be used when trying to set a value for a variable
![Page 44: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/44.jpg)
44
Variables(Implementation)
• It is good practice to declare all of the variables at the start of the program
Dim name as String
Dim age as Integer
Dim rate_of_pay as Single
Dim is short for Dimension
name
A space in memory
age
rate_of_pay
![Page 45: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/45.jpg)
45
Which variable type?
• 0.456 • Jones • -56 • 291• Mike • 17.886 • 3.14 • R2D2
![Page 46: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/46.jpg)
46
Which variable type?
• 0.456 Single• Jones String• -56 Integer• 291 Integer• Mike String• 17.886 Single• 3.14 Single• R2D2 String
![Page 47: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/47.jpg)
47
Exercise
• Which of the following excerpts of code will give errors?:
(a) Dim name as String Name = “Derek”
(b) Dim price as Singleprice = “Derek”
(c) Dim price as Integerprice = 30
![Page 48: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/48.jpg)
48
Formatting Output
• It is good practice to format your output accordingly e.g. if you are outputting a monetary value it should look like this: £3.90
• There is a function in VB6 that takes care of this for you, cleverly it is called the Format function and can be used like this:
Format(price, “currency”) this has the effect of formatting the variable price so that when it is output to the screen it will have a £ sign added automatically
![Page 49: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/49.jpg)
49
Formatting Output
• Some other examples
Format(price, “.0”) to one decimal place
Format(price, “.000”) to 3 decimal places
Format(average, “percent”) ??
Format(time, “.00\s”)??
![Page 50: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/50.jpg)
50
Naming Conventions
• Label – start with lbl
• TextBox – start with txt
• Command Button – cmd
• Picture box – pic
• List Box - lst
![Page 51: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/51.jpg)
51
Variable Names
• Remember that variable names give us an easy way to refer to a storage location in memory– Rather than using the address
• Variables will be used in every program• In large programs there can be hundreds
of variables• Good variable names make a program
more readable
![Page 52: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/52.jpg)
52
• It is therefore very important and good practice to use sensible, meaningful variable names. Sometimes this means using multiple words
• Some no no’s– Whitespace is not allowed
• E.g user age
• Use capitals to de-limit multiple words– userAge– roomWidth
• Or use under score– User_age– Room_width
• Choose one method and stick to it!
Variable Names
![Page 53: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/53.jpg)
53
Commenting
• It is good practice to comment your code so that– You can understand the program– You can see where you left off if you
don’t get a program finished– Makes it readable– Helps maintenance as often in software
companies more than one person will work on a program so comments help others see what you are trying to do more easily.
![Page 54: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/54.jpg)
54
Commenting
• To comment we simply type an apostrophe (‘) after the line of code and anything after it will be ignored by the computer e.g.
Dim name as String ‘ declares a name variable with the type string
![Page 55: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/55.jpg)
55
Making Decisions
• Often the programs we write won’t always go straight from start to finish
• In some programs we will want to make decisions and based on these decisions the program might execute an alternative set of instructions e.g.
If condition then Action 1Action 2ElseAlternative Action 1End If
![Page 56: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/56.jpg)
56
IF statements
• The technique we use to make decisions is an IF statement
IF (userNumber = 1) Then
lblOutput.Caption “ You win the car!”
Else
lblOutput.Caption = “ You Win nothing!”
End If
![Page 57: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/57.jpg)
57
More Complex IF Statements
• Sometimes a decision is not as straightforward as simply IF something = True then do something
• We might need to look at more than one thing being true or a combination of true and false
• We have a set of operators that can be used for this
![Page 58: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/58.jpg)
58
Complex IFs
• For example OAPs to qualify as an OAP, men need to be 65 or over and women need to be 60 or over
• This couldn’t be represented with a normal IF statement
If (sex = “m”) AND (age >= 65) thenPrint “you are an OAP”Else If (sex = “f”) AND (age >= 60) thenPrint “ You are an OAP”ElsePrint “ you are not an OAP, YET!”End IfEnd If
![Page 59: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/59.jpg)
59
Multiple IFs
• It is possible that your program will need to make more than one decision and we can use multiple Ifs to do this e.g
If mark > 70 then grade = “A”
If mark > 60 then grade = “B”
If mark > 50 then grade = “C”
Else
Grade = “Fail”
![Page 60: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/60.jpg)
60
Multiple IFs
• In the example on the previous slide, even if the mark is greater than 70 the other 2 IF statement lines of code will be executed
• This means the program is executing 2 lines of code unnecessarily
• This is inefficient use of resources(processor time/main memory)
![Page 61: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/61.jpg)
61
An efficient alternative
• A more efficient way to code this would be a CASE statement
Select CASE markCase Is >70Grade = “A”Case Is > 60Grade = “B”Case Is > 50Grade = “C”End Select
Select CASE is more efficient because if mark is 75 the grade will be set to “A” and the remaining Case Is lines are ignored, therefore not executing unnecessary code
![Page 62: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/62.jpg)
62
InputBoxes
• So far we have used text boxes to get the user input. We are now going to use a special code word in Visual Basic, InputBox
• When an InputBox is used your program will open a new window with a prompt for the user to enter something
![Page 63: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/63.jpg)
63
InputBoxes
• InputBoxes are used in the following way:
Variable_name = InputBox (“Prompt to the user”, “Title of InputBox”)
Or a real example
UserName = InputBox(“Enter your name”, “Enter Name”)
![Page 64: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/64.jpg)
64
InputBoxes
• This code
UserName = InputBox(“Enter your name”, “Enter Name”)
Would produce the following window when the program is run:
![Page 65: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/65.jpg)
65
MessageBoxes
• InputBoxes are a nice way to collect input to your program as a lot of the work is done for you.
• There is a similar special word we can use for output, MsgBox
• Used like this:
MsgBox (“Thanks for using my program”)
![Page 66: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/66.jpg)
66
MessageBoxes
• This code: MsgBox (“Thanks for using my program”)
• Produces the following:
![Page 67: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/67.jpg)
67
Fixed Loops
• So far, every program you have written starts at the beginning and executes each line till it reaches the end and then stops
• To repeat a program you need to run it again
• It is often useful to be able to repeat a number of lines of a program
![Page 68: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/68.jpg)
68
Fixed Loops
• If we know how many times we want to repeat something we can use a fixed loop
For counter = 1 to 10
Form.Print “Mr McAlpine is the best!”
Next
Will print the statement to the form 10 times
![Page 69: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/69.jpg)
69
Loops using a variable
• If we want a loop that can be repeated a variable number of times we can get the user to input the value for the loop to stop
For counter = 1 to user_inputPrint “this is an example of a variable
loop”Next
![Page 70: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/70.jpg)
70
For…Next other ways to control the loop length
• We can control the loop length using a command called Step
For counter = 1 to 20 Step 2
This would have the effect of adding 2 to the counter each time round the loop rather than the default 1
We can put whatever number we like after the step, depending on how we want the loop to operate
For counter = 10 to 1 Step -1
Would have the effect of going down from 10 to 1
![Page 71: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/71.jpg)
71
Questions
• Write the Visual BASIC coding of a For..Next loop to produce each of the following lists of numbers
A. 3,6,9,12,15,18..33,36B. 0,9,18,27..99C. 10,9,8,7,6,5,4,3,2,1,0D. 0,0.75,1.5,2.25,3,3.75,4.5E. 50,40,30,20,10,0,-10,-20,-30,-40,-50F. 1,4,9,16,25,36,49,64(hint these are all
numbers squared)
![Page 72: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/72.jpg)
72
More Loops
• So far the loops we have used have gone for a set or fixed number of times depending on us setting it up or the user saying how long they want the loop to be
• There is another kind of loop that can be used when we are unsure of when we want a loop to end– Conditional Loop
![Page 73: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/73.jpg)
73
Do..Loop Until
• One type of VB6 loop we can use when we are unsure of the number of times a loop will be repeated is called a Do..Loop Until, it looks like this
DoLines of code to be repeatedLoop Until condition
![Page 74: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/74.jpg)
74
Do..Loop Until
• Here is a real example of this kind of loop:
Do
userInput = InputBox (“What is 2+2?”)
Loop Until userInput = 4
This will keep asking the user the question until they enter 4(the correct answer)
![Page 75: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/75.jpg)
75
While…Wend Loop
• A While loop is also a conditional loop
While ( user_password <> “p4$$w0rd”)
user_password=InputBox(“Enter password”)
Wend
This loop will continue whilst the users entry is NOT p4$$w0rd
![Page 76: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/76.jpg)
76
What kind of Loop?
• Program needs to take in a list of ten names
• Program needs to keep going until the user enters the word “end”
• Program continues until user enters a 4 digit pin
• Program needs to take in four different pieces of information from the user
![Page 77: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/77.jpg)
77
Arrays
• Arrays are useful for times when we need to store lists of related data
• For example 6 test marks for a pupil, we would normally do this
Dim mark1 as integerDim mark2 as integerDim mark3 as integerDim mark4 as integerDim mark5 as integerDim mark6 as integer
![Page 78: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/78.jpg)
78
Arrays
• This would give us 6 independent variables in memory
mark1 mark2 mark3 mark4 mark5 mark6
![Page 79: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/79.jpg)
79
Arrays
• However if we just use this command
Dim mark(5) as integer
We define an array where each variable is referred to by an index e.g. 0,1,2,3
mark0 mark1 mark2 mark3 mark4 mark5
![Page 80: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/80.jpg)
80
Arrays
• An array is very useful as the program can refer to the whole array at once or any single element
• Arrays would normally be used in conjunction with a loop
![Page 81: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/81.jpg)
81
Input Validation
• There is a saying in computing which goes:– Garbage In, Garbage Out (GIGO)
![Page 82: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/82.jpg)
82
![Page 83: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/83.jpg)
83
Input Validation
• It is common for the companies who do things like this to blame it on computer error
• More often these type of errors occur because the program has been fed invalid data
ProgramWrong data in Wrong data out
![Page 84: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/84.jpg)
84
Input Validation
• If we design our program properly we should be able to prevent or at least restrict the amount of wrong data our user is allowed to enter
• An example: we have designed a program that allows teachers to enter their students percentages and it calculates a grade
![Page 85: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/85.jpg)
85
Input Validation
• So the teacher is entering the percentages. They want to enter 59 but are in a hurry and enter 559.
• This would most likely give the student an ‘A’ when they should’ve in fact got a ‘B’– Garbage In, Garbage Out!
• This could be prevented by making it impossible to enter a score of more than 100
![Page 86: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/86.jpg)
86
Input Validation
• A score of over 100 could be described as Invalid in this sense
• Invalid data, is data which makes no sense
• To prevent invalid data being entered we can include our code for data input in a conditional loop that will only stop when valid data is entered
![Page 87: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/87.jpg)
87
Invalid Data
• A program asks a user to enter a date in day/month/year format. Give an example of an entry that would be considered invalid and also a valid entry
• A program asks a user to enter a 5 digit number, give an example of an invalid entry and a valid entry.
![Page 88: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/88.jpg)
88
Input Validation
• Note that Input Validation does not stop mistakes from occurring it simply stops invalid data being entered.– For example it would stop a percentage of 105
being entered but if someone entered 59 instead of 49, validation does not pick up on this
• The process of catching erroneous data is called verification, which is outside the scope of this course
![Page 89: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/89.jpg)
89
Input Validation
• The process of input validation always follows a standard pattern
• Standard patterns save programmers time when programming
• A pattern like this is called a standard algorithm
![Page 90: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/90.jpg)
90
Input Validation
• Here is a simple version of the standard algorithm for input validation
Do
Prompt user for valid input
If input is invalid, warn user
Loop until data is valid
![Page 91: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/91.jpg)
91
Other Standard Algorithms
• Input Validation is an example of a Standard Algorithm
• There are 4 others that you need to know about
• Finding a minimum/maximum, Counting Occurrences and Linear Search
![Page 92: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/92.jpg)
92
Standard Algorithms
• The pattern for Input validation is the same in all scenarios– This saves programmers time when
designing programs
• There are many other instances of these patterns that are re-useable– They are called STANDARD
ALGORITHMS
![Page 93: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/93.jpg)
93
Finding Minimum/Maximum
• These algorithms search lists of numbers and return the value of the minimum/maximum
• E.g in the following list
14, 67, 24, 2, 69, 9, 100, 101
• Minimum?
• Maximum?
![Page 94: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/94.jpg)
94
Finding Min
Will usually be used in conjunction with an array
Set min = first element in arrayFor length of arrayIf current array element < min thenMin = current array elementNext
Print min
![Page 95: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/95.jpg)
95
Finding Max
Will usually be used in conjunction with an array
Set max = first element in arrayFor length of arrayIf current array element > max thenMax = current array elementNext
Print min
![Page 96: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/96.jpg)
96
Counting Occurrences
• Works it’s way through a list of numbers, as it does, it counts the amount of times a certain value appears
• E.g. how many times does 3 appear here?
4, 7, 3, 8, 6, 3, 9, 0, 3, 5
![Page 97: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/97.jpg)
97
Counting Occurrences
Usually involves using an array
To_find = “Dave”
For length of arrayIf current array element = to_findCounter = counter + 1Next
Print Counter
![Page 98: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/98.jpg)
98
Linear Search
• Searches through a list looking for a particular item and returns where in the list the item appears
e.g. search for blue
Red, green, yellow, orange, blue, pink
5 would be returned as blue is the 5th item in the list
![Page 99: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/99.jpg)
99
Linear Search
Usually used along with an array
Name = InputBox “Enter a name to be found”
For counter = 0 to length of arrayIf namearray(counter) = NameDisplay “Name found at “ & counterEnd IfNext
![Page 100: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/100.jpg)
100
Which standard algorithm would we use to solve these
problems?• Search through a list of names to find at
what place the name Steve appears• Make sure the user enters a number
between 1 and 10• Find the month in a list with the lowest
rainfall• Counting the number of times Tiger
Woods has won the US Masters from a list of US Master winners
![Page 101: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/101.jpg)
101
Questions
• Which standard algorithm would be used by the national census to:
• Find out how many people called Mary live in the UK?
• Find out the oldest person living in the UK?
• Discover whether or not there was an individual living in the UK call ‘Stan D. Ard-al-Gorithm’?
![Page 102: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/102.jpg)
102
Pre-Defined Functions
• These carry out standard operations that are commonly used
• They exist for strings (text) and numbers (Integers)
![Page 103: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/103.jpg)
103
Pre-defined String Functions
• UCase (string) capitalises the string• LCase (STRING) puts string to lower case• Len (string) returns the length of the string• Mid$(string, start point, lengthrequired)
returns a section of the string starting at the character specified by the start point and the length specified by the lengthrequired
![Page 104: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/104.jpg)
104
SubStrings
• Essentially taking a chunk out of a string to use for something else: like generating a password or to look for a pattern in a string
• Using Mid$(string to be used, start position, number of letters in the
substring)
![Page 105: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/105.jpg)
105
Concatenation
• Sometimes we will want to output multiple values using a single line of code e.g
MsgBox(“Your total bill is: “ & totalCost)OrMsgBox(“Customer Name: “ & name & VbCrlf &
“Customer Address: “ & address)
Using the & sign is called ConcatenationIt can be used as many times as necessary to get
your output looking like you want it
![Page 106: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/106.jpg)
106
Concatentation
• Remember though that there is a Format function so:
• Something like
MsgBox(Format(price, “Currency”))
Will have the same effect as
MsgBox (“£” & price)
![Page 107: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/107.jpg)
107
Questions
• Match these descriptions to the pre-defined function
Description Pre-defined function
Returns the ASCII code of character Mid$
Selects a group of characters out of a string Asc
Turns any character into upper case LCase
Takes an ASCII code and returns the character it UCaserepresents
Changes any character to lower case Len
Counts the number of characters in a string Chr$
![Page 108: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/108.jpg)
108
Questions Continued
• If sentence = “What is 25 times 8?”), what would be the output from:– A) Mid$(sentence,1,1)– B) Mid$(sentence,1,4)– C) Mid$(sentence,9,2)– D) Mid$(sentence,19,1)
![Page 109: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/109.jpg)
109
Pre-Defined Numeric Functions
• INT(variable containing a fraction) would remove the fractional part, leaving the whole number
• ROUND(variable to be rounded) rounds the number to the NEAREST whole number
• SQR(variable) gives the square root of any number
![Page 110: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/110.jpg)
110
User Defined FunctionsWe can create functions of our own e.g
Function calc_area(length as single, breadth as single) as singleDim area as single
Area = length * breadthCalc_area = AreaEnd Function
We can then use the function as follows
Private sub cmd_click()Dim length as singleDim breadth as singleDim area as single
Area = calc_area(length, breadth)
Form1.Print(Area)End Sub
As the function returns a value
![Page 111: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/111.jpg)
111
Testing
• Any product created will go through rigorous testing
• A wide range of conditions will be used e.g. not only expected inputs in the case of a program– These will be planned at the
design stage• Testing will be systematic and
comprehensive– Systematic means the testing
is planned and not just random tests
– Comprehensive means every aspect is tested
Testing can only prove the presence of bugs, not their absence. Testing finds bugs, de-bugging removes those bugs
![Page 112: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/112.jpg)
112
Normal Testing
• Make sure the program does what it should when being used normally
• A program expects a number to be entered between 0 AND 40– Normal testing would test that the
program did what it should for numbers 1-39
![Page 113: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/113.jpg)
113
Extreme/Boundary testing
• Making sure the program can handle values at the extreme or boundary of what is considered normal.
• Using our 0 to 40 program– Extreme tests would be -1, 0, 40, 41
![Page 114: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/114.jpg)
114
Exceptional testing
• Making sure the program can handle situations or inputs that are unexpected or that the program is not designed for
• Using our 0-40 program– Things like 3000000, y , n , -45690,
hello
![Page 115: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/115.jpg)
115
What kind of testing
• A) program looking for a person’s age and the test data used is: hello, 1000000, steve, oioi70780
• B) program looking for a 4 digit pin code and the data used is: 0000, 0001, 9999
• C) program looking for the price of a slab: 0.50, 1.23, 2.45, 5.60
![Page 116: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/116.jpg)
116
Testing and Robustness
• Testing all conditions provides useful evidence about he robustness of the software– Robustness is the ability of the program
to cope with erroneous/unexpected data
![Page 117: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/117.jpg)
117
Testing
• Testing is carried out by Independent Test teams– Other programmers from within the
organisation– Or perhaps contractors– Or potential clients– Or combination of all of the above
• Testing is carried out at various stages
![Page 118: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/118.jpg)
118
Acceptance Testing
• Acceptance testing is sometimes called Beta testing
• Carried out on the premises where the software will be used, by the people who will use it– Given unrestricted access– Allowed to enter unpredictable input to
test the behaviour of the program
![Page 119: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/119.jpg)
119
Exhaustive Testing
• Testing functionality with all possible valid and invalid data– Is this possible?
• So how much is enough?– How important is the project?
![Page 120: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/120.jpg)
120
Documentation
• After testing has been completed we move onto stage 5 of the development process – Documentation
• Any product you buy, software or hardware will come with a User Guide to tell you how to use the product– This may also contain a tutorial taking you
through the use of the product step by step• Becoming more prevalent to use an
electronic format– More eco-friendly but can also be updated
with the software
![Page 121: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/121.jpg)
121
Documentation
• As well as the user guide for the software, there will also be a Technical Guide of some sort
• Usually this is of no interest to most users, but will contain information about the specification of computer required– E.g. RAM, how fast a processor and which
Operating System the computer needs• Will also contain instructions on
installation of the software• Might also contain information on trouble
shooting
![Page 122: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/122.jpg)
122
Evaluation
• Stage 6 and the final stage before the product is distributed
• Involves reviewing the software to see if it is of the quality required
• We will look at three headings– Fitness for Purpose– User Interface– Readability
![Page 123: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/123.jpg)
123
Evaluation
• User Interface– Is program easy to use?– Is it clear what each menu, command
and button is for?– Could it be improved in any way?
![Page 124: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/124.jpg)
124
Evaluation
• Fitness for Purpose– Does software do as it should under all
reasonable conditions?– Check against the program
specification to make sure (analysis stage)
– Look at test results and making sure the program is free of bugs
![Page 125: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/125.jpg)
125
Evaluation
• Readability– No direct concern of the user– Important for other programs to
understand how the program works– Is it possible for another programmer to
read and understand the code• Needs to be if there will be updates
performed at a later date
![Page 126: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/126.jpg)
126
Evaluation(Higher)
The following questions will be asked:• Is the program robust?• Is the program reliable?• Is the program reliable?• Is the program portable?• Is the program efficient?• Is the program maintainable?
These are expanded in the notes
![Page 127: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/127.jpg)
127
Evaluation
• What 3 criteria are be used for evaluating software?
• What is the relationship between pseudocode and a structure diagram?
• Name 2 items of documentation usually provided with a software package, and describe what you would expect each one to contain.
• What 3 types of testing should be applied to any software?
• Describe 2 examples of maintenance that would be required on a game program.
![Page 128: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/128.jpg)
128
Scope
• Variables can have 2 types of scope– GLOBAL and LOCAL
• Global variables are created outside any subs, functions or procedures and can be used/seen by all subs/functions/procedures
• Local variables are created inside subs and can only be seen/used within that sub
![Page 129: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/129.jpg)
129
Modularity
• Scope gives programmers freedom to create modules without worrying that they are creating variables in their module that conflict with the variables created by the other programmers– E.g. we are creating a school management
program. I am creating the module for pupils and I use the variable firstName. You are creating the module for the teachers and use a variable called firstName. As long as these variables are LOCAL to my sub, e.g. created within my sub there will be no conflict
![Page 130: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/130.jpg)
130
Parameter Passing
• A parameter is just a variable being passed into a subroutine
• Very important programming concept– Ensures variables don’t interfere with
each other– Keeps programs reliable
![Page 131: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/131.jpg)
131
Parameter Passing
• In real programming situations, several programmers are involved in the creation of the program
• The each create sub procedures
Private sub valid_age(byval age as integer)
![Page 132: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/132.jpg)
132
Parameter Passing
Private sub valid_age(byval age as integer)
To execute this sub procedure we would put the line
Call valid_age(person_age)
Note that the parameter passed does not match the variable, this is ok and will still work. As long as person_age is an integer
This allows programmers to write procedures and not worry about what other programmers are calling variables
![Page 133: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/133.jpg)
133
ByVal
• Used if you only need to use the value of the variable
• You won’t be able to change the value of the variable
• You send a copy of it that is discarded after use– Like giving someone a photocopy, they
can write on it etc and throw it away after use, you keep the original
![Page 134: Software Development](https://reader035.fdocuments.net/reader035/viewer/2022070417/56815505550346895dc2ef3d/html5/thumbnails/134.jpg)
134
ByRef
• Used if you need to change the value of the variable
• They are passed in, updated and passed out for future use– Like giving someone your master copy,
if they change it and give you it back, the changes are permanent