Mark Dixon, SoCCE SOFT 131 Page 2
Session Aims & Objectives• Aims
– tidy up from last session– introduce you to testing and debugging process– introduce you to graphics
• Objectives, by end of this week’s sessions, you should be able to:
– Test program– Identify and correct simple logical and syntax errors– put bitmap (raster) graphics into you applications– draw simple vector graphics
Mark Dixon, SoCCE SOFT 131 Page 4
Testing & Debugging: Errors• 3 error types :
– syntax: computer unable to understand your instructions (program does not execute), e.g.
• variable not defined (probably most common)
– run-time: program can't execute instruction and exits (future lecture)
• device not available
– logical: program executes but does not not match specification (do what was intended), e.g.
• clicking on button does nothing, when you thought you attached code to it
• clicking on blue button changes colour to red (when it should change to blue)
Music Player
Mark Dixon, SoCCE SOFT 131 Page 5
• Computer – just symbol matching– No intelligence
Example 1: Hello Errors
Sub Command1_Cluck LabelL.Caption = "Hello"End Sub
L instead of 1: causes syntax error (variable not defined)
u instead of i: causes logical error (Command1 button does nothing)
Mark Dixon, SoCCE SOFT 131 Page 6
Exercise 1: Errors
• The following is from exercise 1 (v1),– Spot the errors (you should find 6), and– decide whether they are syntax or logical
Private Sub btnBlue_Cluck() lblResult.BackColor = vbRedEnd Sub
Private Sub btnRed_lick() lblResult.BackColor vbRedEnd Sub
Private Sub lb1Result_DblClick() lblResult.BackColour = vbWhiteEnd Sub
Mark Dixon, SoCCE SOFT 131 Page 7
Verification & Validation
• Verification:– 'Are we building the product right?'– Does software match software requirements
specification?
• Validation:– 'Are we building the right product?'– Does the software requirements specification
meet the user requirements?
Mark Dixon, SoCCE SOFT 131 Page 8
Debugging: Testing
• Functional Decomposition– break it into logical chunks
• Incremental Development– type a bit– test it
• Testing– test all/most combinations
• Regression Testing– repeat all previous tests
Mark Dixon, SoCCE SOFT 131 Page 9
Types of Graphics: Raster
• Raster graphics – made of dots (pixels – picture elements)– suitable for complex, static pictures (e.g. photos)– difficult to change programmatically– loses quality when enlarged
Mark Dixon, SoCCE SOFT 131 Page 10
Types of Graphics: Vector
• Vector graphics – made of objects (lines, circles, etc.)– suitable for simple, dynamic pictures (diagrams)– No loss of quality when enlarged
Mark Dixon, SoCCE SOFT 131 Page 11
Picture Control
• Methods (vector graphics)– Line: draws a straight line between 2 points– Circle: draws a circle– PSet: draws a dot (point)– Cls: clears (screen) drawing area
• Properties– Picture: allows display of bitmap (raster graphic) as
background
Mark Dixon, SoCCE SOFT 131 Page 12
Graphics: Grid System
• the origin (position 0,0) is at top left– in mathematics it is always bottom left
200010000
0
1000
Mark Dixon, SoCCE SOFT 131 Page 13
Example 2: Shapes
• Form and Picture Box control support graphics methods:
0 200010000
1000
picDisplayArea.Line (500, 200)-(1900, 800)picDisplayArea.Line -(2600, 600)picDisplayArea.Line -Step(-600, -400)
picDisplayArea.PSet (1500, 1000)picDisplayArea.Circle (700, 900), 300
Shapes
Mark Dixon, SoCCE SOFT 131 Page 14
Example 3: StickMan
• Enabled property (true or false)
StickMan
200010000
0
1000
Mark Dixon, SoCCE SOFT 131 Page 16
Example 5: Picture Viewer– LoadPicture function:
picDisplay.Picture = LoadPicture("C:\Cat.jpg")– Pattern property (of file list)
Mark Dixon, SoCCE SOFT 131 Page 17
Example 6: Music Player v3
V3
Option Explicit
Private Sub drvMain_Change() dirMain.Path = drvMain.DriveEnd Sub
Private Sub dirMain_Change() filMain.Path = dirMain.PathEnd Sub
Private Sub filMain_Click() mmcMain.Command = "Close" mmcMain.FileName = filMain.Path & "\" & filMain.FileName mmcMain.Command = "Open" pgbMain.Max = mmcMain.Length pgbMain.Value = 0End Sub
Private Sub mmcMain_StatusUpdate() pgbMain.Value = mmcMain.PositionEnd Sub
Private Sub mmcMain_Done(NotifyCode As Integer) filMain.ListIndex = filMain.ListIndex + 1 mmcMain.Command = "Play"End Sub