Document Sample
Variables Powered By Docstoc
					Software Development



• 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

                    D.McAlpine               2

• 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

                    D.McAlpine              3
• What is the meaning of the term hardware?
• Give three examples of software.
• Complete the following table:
   Item                Hardware     software
   Windows XP
   An e-mail
   Internet Explorer
   Computer game
   Word processor
                       D.McAlpine              4
   Digital camera
    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

                       D.McAlpine              5
    Development Process
It 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
n   e   m    e   c
                       v          a
        p              a          i
a   s        s   u
        l        m     l          n
l   i   e    t
                 e     u          t
y   g   m    i   n
s   n   e    n   t
                       a          e
        n              t          n
i            g   a
        t        t     i          a
s       a        i     o          n
        ti       o
        o        n
                       n          c
        n            D.McAlpine   e      6
    Software Development
• 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.
                    D.McAlpine          7
          Who does it?

• The systems
  analyst is the
  person who
  for the

                   D.McAlpine   8
    Skills of the Systems
• Usually a skilled and experienced
• Good people skills
• Good communication skills

                   D.McAlpine         9
      What do they do?

• Interview clients
• Observation notes – of existing
• Questionnaires

• All of these are categorised as
  requirements elicitation

                   D.McAlpine       10
  The Importance of Being
• 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

                         D.McAlpine                   11
 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
                     D.McAlpine               12
 Blob Diagram(analysis)

• Used to determine the inputs and
  outputs to a program, using tea
Tea bag
                                           Used tea
                      Making tea
   water                                   Boiled water

           milk                            Cup of tea

                              D.McAlpine              13
            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

                          D.McAlpine                   14
  Blog Entry: The Software
   Development Lifecycle
• Higher                     • Int2
  – The 7 stages of the                – The 7 stages of the
    SD Lifecycle                         SD Lifecycle
  – Analysis – What                    – Analysis: What
    happens here, who                    happens at this
    does it, how do                      stage and what is
    they do it and what                  produced
    do they produce                    – Blob diagramy
  – Techniques – what
    techniques are
                          D.McAlpine                       15
  Blog Entry: The Software
   Development Lifecycle
• Update your blog on the Software
  Development lifecycle to include all
  of the new things you have learned
  about each stage.

                   D.McAlpine            16
    Software Development
• 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
                      D.McAlpine             17
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 kettle
2. Boil kettle
3. When kettle boiled pour hot water in cup
4. Add tea bag, milk and sugar

We can then use this as the design for our program

                               D.McAlpine                    18
             Your turn

• Write the Pseudocode for the

• 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

                    D.McAlpine             19
              Structure Diagram

  • Fairly simple, take the tea making
                      Making tea

Fill kettle   Boil kettle    When kettle         Add milk,   Stir
                             boiled pour         sugar
                             into cup

                                    D.McAlpine                      20
             Structure Diagram(with
                   data flow)                 Area of rectangle

Length                              Length
                   Get sizes                          Calculate area              Display area        area
breadth                             breadth                                area

 Find out length         Find out                            Area =
                         breadth                        length x breadth

    • Indicates what variables are passed in
      and out of procedures                          D.McAlpine                                  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

                    D.McAlpine            22
   Software Development
• Implementation – This is the process
  of turning the design into a suitable
  programming language. We will use
  a High Level Language, called Visual
• Testing – A great deal of time is
  spent on testing. A wide range of
  conditions will be tested. Normal,
  extreme and exceptional testing.

                   D.McAlpine         23

• 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

                   D.McAlpine         24

• The 7th and last stage of the
  development process
  – Continuous
• 3 types of maintenance
  – Corrective
  – Perfective
  – Adaptive

                    D.McAlpine    25
• Corrective
  – Fix bugs that appear when program is in use
  – Company might make downloadable “patch”
• Perfective
  – Adding new features
  – Might mean a new a version of the software is
• 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      D.McAlpine                   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
                          D.McAlpine                27
                     ANALYSIS – the user
                     requirements are
                     determined at this stage

 MAINTENANCE-                                   DESIGN – Software and
 upgrading                                      Program design are
                                                detailed at this stage

refinements          DEVELOPMENT
DOCUMENTATION –                                 IMPLEMENTATION –
technical and user                              actual program put into
guide drawn up.                                 operation

                     TESTING – errors and
                     bugs corrected
    High Level Languages
• Just like human language, there are
  many different types of programming
• Each has been designed to solve a
  specific type of problem
• Each has it‟s own strengths and

                  D.McAlpine        29
    High Level Languages
• Visual Basic is an example of a High
  Level Language
• High Level Languages contain
  „normal‟ words and are close to
• This makes them relatively easy for
  us to understand
• However, as we know computers
  only understand binary
                   D.McAlpine            30
  Low Level Languages

• Low level languages are closer to the
  language that the computer can
• It is very difficult to track down and
  fix bugs using these languages

                   D.McAlpine          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
• 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
                         D.McAlpine               32
• 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
                      D.McAlpine            33
 High/Low Level Languages

• High                  • Low
  –   Visual Basic                – Machine Code
  –   Pascal                      – Assembler
  –   Logo
  –   Java

                     D.McAlpine                    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
                          D.McAlpine    35

• There are 2 different types of
  – Compiler and Interpreter
• Each has strengths and weaknesses

                    D.McAlpine     36

• 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
                      D.McAlpine             37

• 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
                    D.McAlpine             38
• 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
                  D.McAlpine            39
• Name the two main types of translator
• 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?

                     D.McAlpine            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

                      D.McAlpine            41
    Scripting Language and
• This unit is mostly concerned with the process of
  developing stand alone applications in high level
• 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
• They customise applications
                             D.McAlpine                       42

• What is a macro?
• What type of language is used to
  write macros?
• What are the advantages of using
• Describe 2 examples where a macro
  could be useful.

                 D.McAlpine       43

• 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
                      D.McAlpine            44

• It is good practice to declare all of the
  variables at the start of the program A space in

Dim name as String                   name

Dim age as Integer                     age
Dim rate_of_pay as Single             rate_of_pay

Dim is short for Dimension

                        D.McAlpine                   45
     Which variable type?
•   0.456
•   Jones
•   -56
•   291
•   Mike
•   17.886
•   3.14
•   R2D2
              D.McAlpine    46
     Which variable type?
•   0.456    Single
•   Jones    String
•   -56      Integer
•   291      Integer
•   Mike     String
•   17.886   Single
•   3.14     Single
•   R2D2     String
                       D.McAlpine   47
•   Which of the following excerpts of code will give

(a) Dim name as String
    Name = “Derek”

(b) Dim price as Single
    price = “Derek”

(c) Dim price as Integer
    price = 30
                           D.McAlpine               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:
• 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

                             D.McAlpine                   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”)??

                    D.McAlpine              50
     Naming Conventions

•   Label – start with lbl
•   TextBox – start with txt
•   Command Button – cmd
•   Picture box – pic
•   List Box - lst

                     D.McAlpine   51
        Variable Names
• Remember that variable names give us an
  easy way to refer to a storage location in
  – 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

                       D.McAlpine           52
            Variable Names
• 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!

                                  D.McAlpine                53
• 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.    D.McAlpine           54

• 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

                    D.McAlpine            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 1
Action 2
Alternative Action 1
End If               D.McAlpine           56
         IF statements
• The technique we use to make decisions
  is an IF statement
IF (userNumber = 1) Then
  lblOutput.Caption “ You win the car!”
  lblOutput.Caption = “ You Win nothing!”
End If

                   D.McAlpine         57
       More Complex IF
• 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
                   D.McAlpine         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) then
Print “you are an OAP”
If (sex = “f”) AND (age >= 60) then
Print “ You are an OAP”
Print “ you are not an OAP, YET!”
End If
End If

                              D.McAlpine                    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”
Grade = “Fail”
                      D.McAlpine               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
                   D.McAlpine          61
  An efficient alternative
• A more efficient way to code this would be a CASE

Select CASE mark
Case Is >70
Grade = “A”
Case Is > 60
Grade = “B”
Case Is > 50
Grade = “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
                              D.McAlpine                    62

• 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

                  D.McAlpine         63

• InputBoxes are used in the following

Variable_name = InputBox (“Prompt to the user”, “Title of InputBox”)

Or a real example

UserName = InputBox(“Enter your name”, “Enter Name”)

                                 D.McAlpine                    64

• This code

UserName = InputBox(“Enter your name”, “Enter Name”)

Would produce the following window when the program
 is run:

                         D.McAlpine             65

• 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”)
                    D.McAlpine            66

• This code: MsgBox (“Thanks for using my program”)

• Produces the following:

                         D.McAlpine               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
                       D.McAlpine           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!”

Will print the statement to the form 10 times

                      D.McAlpine                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_input
Print “this is an example of a variable
                    D.McAlpine            70
    For…Next other ways to
     control the loop length
• We can control the loop length using a command called

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

                                D.McAlpine                   71
•    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,36
B.   0,9,18,27..99
C.   10,9,8,7,6,5,4,3,2,1,0
D.   0,0.75,1.5,2.25,3,3.75,4.5
E.   50,40,30,20,10,0,-10,-20,-30,-40,-50
F.   1,4,9,16,25,36,49,64(hint these are all
     numbers squared)
                        D.McAlpine             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

                       D.McAlpine      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

Lines of code to be repeated
Loop Until condition
                    D.McAlpine             74
          Do..Loop Until
• Here is a real example of this kind of loop:

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)

                      D.McAlpine              75
      While…Wend Loop
• A While loop is also a conditional loop

While ( user_password <> “p4$$w0rd”)
user_password=InputBox(“Enter password”)

This loop will continue whilst the users entry
  is NOT p4$$w0rd

                       D.McAlpine            76
     What kind of Loop?
• Program needs to take in a list of ten
• 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
                   D.McAlpine          77
       Input Validation

• There is a saying in computing which
  – Garbage In, Garbage Out (GIGO)

                   D.McAlpine        78
D.McAlpine   79
            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

Wrong data in                          Wrong data out

                          D.McAlpine                    80
       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

                   D.McAlpine         81
        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

                      D.McAlpine               82
       Input Validation

• A score of over 100 could be
  described as Invalid in this sense
• Invalid data, is data which makes no
• 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
                   D.McAlpine         83
          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
• A program asks a user to enter a 5
  digit number, give an example of an
  invalid entry and a valid entry.

                  D.McAlpine         84
        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
• The process of catching erroneous data is
  called verification, which is outside the
  scope of this course
                       D.McAlpine               85
       Input Validation

• The process of input validation
  always follows a standard pattern
• Standard patterns save
  programmers time when
• A pattern like this is called a
  standard algorithm

                   D.McAlpine         86
        Input Validation

• Here is a simple version of the
  standard algorithm for input

Prompt user for valid input
If input is invalid, warn user
Loop until data is valid
                     D.McAlpine     87
 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

                   D.McAlpine           88
    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

                    D.McAlpine          89
Finding Minimum/Maximum

• These algorithms search lists of
  numbers and return the value of the
• E.g in the following list

14, 67, 24, 2, 69, 9, 100, 101
• Minimum?
• Maximum?
                    D.McAlpine          90
            Finding Min
Will usually be used in conjunction with an

Set min = first element in array
For length of array
If current array element < min then
Min = current array element

Print min

                      D.McAlpine              91
            Finding Max
Will usually be used in conjunction with an

Set max = first element in array
For length of array
If current array element > max then
Max = current array element

Print min

                      D.McAlpine              92
  Counting Occurrences

• Works it‟s way through a list of
  numbers, as it does, it counts the
  amount of times a certain value
• E.g. how many times does 3 appear

4, 7, 3, 8, 6, 3, 9, 0, 3, 5
                      D.McAlpine       93
  Counting Occurrences
Usually involves using an array

To_find = “Dave”

For length of array
If current array element = to_find
Counter = counter + 1

Print Counter
                      D.McAlpine     94
          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
                       D.McAlpine            95
         Linear Search
Usually used along with an array

Name = InputBox “Enter a name to be
For counter = 0 to length of array
If namearray(counter) = Name
Display “Name found at “ & counter
End If

                     D.McAlpine       96
 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
• Counting the number of times Rangers
  have won the league from a list of league
  winners             D.McAlpine              97
• 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.
                      D.McAlpine            98
  Pre-Defined Functions

• These carry out standard operations
  that are commonly used
• They exist for strings (text) and
  numbers (Integers)

                  D.McAlpine            99
          Pre-defined String
•   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

                         D.McAlpine             100

• 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
• Using
Mid$(string to be used, start position, number of letters in the substring)

                                       D.McAlpine                      101
• Sometimes we will want to output multiple
  values using a single line of code e.g

MsgBox(“Your total bill is: “ & totalCost)
MsgBox(“Customer Name: “ & name & VbCrlf &
   “Customer Address: “ & address)

Using the & sign is called Concatenation
It can be used as many times as necessary to get
    your output looking like you want it
                        D.McAlpine                 102

• Remember though that there is a
  Format function so:
• Something like
MsgBox(Format(price, “Currency”))

Will have the same effect as
MsgBox (“£” & price)

                   D.McAlpine       103
• 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            UCase

Changes any character to lower case                         Len

Counts the number of characters in a string                 Chr$

                                       D.McAlpine                          104
   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)

                    D.McAlpine        105
     Pre-Defined Numeric
• 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
                  D.McAlpine        106
    User Defined Functions
We can create functions of our own e.g

Function calc_area(length as single, breadth as single) as single
Dim area as single

Area = length * breadth
Calc_area = Area
End Function

We can then use the function as follows

Private sub cmd_click()
Dim length as single
Dim breadth as single
Dim area as single

Area = calc_area(length, breadth)

End Sub

As the function returns a value

                                            D.McAlpine              107
• 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 integer
Dim mark2 as integer
Dim mark3 as integer
Dim mark4 as integer
Dim mark5 as integer
Dim mark6 as integer

                     D.McAlpine          108

        • This would give us 6 independent
          variables in memory

mark1    mark2   mark3    mark4          mark5   mark6

                            D.McAlpine               109

        • 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
                                D.McAlpine             110

• 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

                   D.McAlpine        111
 • 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
     – Systematic means the testing
       is planned and not just random
     – 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                        D.McAlpine              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

                    D.McAlpine           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

                     D.McAlpine            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,

                     D.McAlpine            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
                   D.McAlpine             116
 Testing and Robustness

• Testing all conditions provides useful
  evidence about he robustness of the
  – Robustness is the ability of the program
    to cope with erroneous/unexpected

                     D.McAlpine            117
• Testing is carried out by Independent
  Test teams
  – Other programmers from within the
  – Or perhaps contractors
  – Or potential clients
  – Or combination of all of the above
• Testing is carried out at various
                    D.McAlpine           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

                     D.McAlpine               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?

                        D.McAlpine      120
• 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

                        D.McAlpine                121
• 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
                        D.McAlpine              122

• 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
                    D.McAlpine           123

• 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?

                    D.McAlpine            124

• Fitness for Purpose
  – Does software do as it should under all
    reasonable conditions?
  – Check against the program
    specification to make sure (analysis
  – Look at test results and making sure
    the program is free of bugs

                     D.McAlpine           125

• 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

                        D.McAlpine            126
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

                      D.McAlpine         127
• What 3 criteria will be used for evaluating
  software in this unit(Int 2)?
• 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
• Describe 2 examples of maintenance that would
  be required on a game program.

                         D.McAlpine              128
• Variables can have 2 types of scope
• Global variables are created outside
  any subs, functions or procedures
  and can be used/seen by all
• Local variables are created inside
  subs and can only be seen/used
  within that sub
                   D.McAlpine            129
• 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
                       D.McAlpine               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

                     D.McAlpine              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)

                     D.McAlpine               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
                          D.McAlpine                 133
• 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

                    D.McAlpine          134

• 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

                     D.McAlpine           135
  Int 2                                     Higher
• Belinda‟s Slab                 • Task using Select Case
  Calculator(P17)                  (P20) Section 2
    – Blob diagram, Form Design, • Lucky Prize Draw P8
       Pseudocode, Code listing,   Section 4
       testing, User Guide       • Book Orders Program +
• Colour Changer(p59)              Evaluation of Book Orders P
    – Blob Diagram, Form           24 Section 6 + Testing
       Design, Pseudocode, Code • Task 7.7.2 and 7.7.3 on
       listing, User Guide         page 17 section 7
• Times table program(P73)       • Task 7.8.2 on P23 section 7
    – Code, UserGuide, Testing     + User Guide + Analysis +
• Any 2 of the following code      Design
   – Age Program, PIN program,
     Year Program (all on P94)

                             D.McAlpine                   136