Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions
Core VB steps 1.Design an interface (create paper prototype) 2.Turn this design into a VB form 3.Code events to occur 4.Test and debug
Screen Design
Step 1: Create a Paper Prototype Get a piece of paper and pencil Sketch the user interface display boundaries Sketch on the input areas Sketch on the output areas Sketch on the interactive elements (e.g. buttons) Sketch on any information areas Scribble notes onto design to explain each part of the sketch
Have a go… Design a single form application interface that allows a user to convert currencies –Take a piece of paper… that’s the interface form –Sketch the overall shape of the interface form input, output, interactive (button) areas any information areas –Scribble some notes to say what controls do…
Core VB steps 1.Design an interface (sketch paper prototype) 2.Turn this design into a VB form 3.Code events 4.Test and debug 1.Design an interface (sketch paper prototype) 2.Turn this design into a VB form 3.Code events 4.Test and debug
Step 2: Turning design into a form Place controls onto a VB form –Input areas (e.g. textboxes, check box, radio button, list box) –Output areas (e.g. labels, pictures, lines,) –Information areas (e.g. labels, progressive bar) –Interactive elements (e.g. command buttons, menu items) Arrange the layout & size of controls –Information should flow vertically or horizontally –Top → Bottom, Left → Right (similar to reading a book) –Most important information at top left Edit the properties of a control –E.g. name and text contents –Access Keys –Tab Index Properties
Step 2: Turning design into a form
Qualities of a Good Programmer Correct scope is used Accurate & consistent naming Code is documented well Code is broken into modules Code is in logical sequence Correct selection structures are used
Structured Programming This is about building blocks of code
Structured Programming Simple Sequence Lines of codes to undertake tasks
Structured Programming Control Structure e.g. selection Lines of codes to undertake tasks If condition Then Lines of codes to undertake tasks Else Lines of codes to undertake tasks EndIf Lines of codes to undertake tasks
Structured Programming Control Structure e.g. repetition Lines of codes to undertake tasks Do While condition Lines of codes to undertake tasks Loop Lines of codes to undertake tasks
Structured Programming Form Event Procedures Click on Clear Button Lines of codes to undertake tasks Enter Text into Text Box Lines of codes to undertake tasks Click on Calculate Button Lines of codes to undertake tasks Do While condition Lines of codes to undertake tasks Loop Lines of codes to undertake tasks Click on Exit Button Lines of codes to undertake tasks
Structured Programming Form Level Entry Form Enter Text into Text Box Lines of codes to undertake tasks Click on Exit Button Lines of codes to undertake tasks Calculate Form Click on Clear Button Lines of codes to undertake tasks Enter Text into Text Box Lines of codes to undertake tasks Click on Exit Button Lines of codes to undertake tasks Display Form Click on Clear Button Lines of codes to undertake tasks Click on Exit Button Lines of codes to undertake tasks
Structured Programming Event Procedure/User Procedure Click on ThrowIt Button Lines of codes to undertake tasks Enter Text into Entry Box Lines of codes to undertake tasks Click on Result Button Lines of codes to undertake tasks User Defined Procedure Lines of codes to undertake tasks
User Defined Procedures Two purposes 1.To execute a block of code (User Defined) Sub Procedure 2.To execute code and return a result Function Procedure
these are given a name look very similar to an event Procedure activated using the Call command line of code Call CalcTimeOfDay line of code Private Sub CalcTimeOfDay() lines of code End Sub 1. User Defined Sub Procedure
2. Function Procedure these are given a name look very similar to an event Procedure usually activated with the "=" assignment character line of code IntTotalSpeed = CalculateSpeed () line of code Private Function CalculateSpeed() As Integer lines of code Return SomeValue End Function
Passing Variables
There are two ways we can pass data in the form of variables, in and out of sub routines/functions 1.Passing By Value ByVal –Sub routine gets a copy of the variable –Variable’s original value is not altered 2.Passing By reference ByRef –Sub routine is told variable location (reference) –Variable’s original value is altered
Passing Variables Private Sub YoyoPause (By Ref strYoTime As String) lines of code End Sub Private Function SpeedCalculate(ByVal intSpeedTot as Integer) As Integer lines of code Return SomeValue End Function
THE END of the lecture