Presentation is loading. Please wait.

Presentation is loading. Please wait.

CW-V1 SDD 0601 Principals of Software Design and Development Variables Constants Data Types Error Handling Starter: BlockbustersBlockbusters.

Similar presentations


Presentation on theme: "CW-V1 SDD 0601 Principals of Software Design and Development Variables Constants Data Types Error Handling Starter: BlockbustersBlockbusters."— Presentation transcript:

1 CW-V1 SDD 0601 Principals of Software Design and Development Variables Constants Data Types Error Handling Starter: BlockbustersBlockbusters

2 CW-V1 SDD 0602 Learning Objectives Describe Variables and Constants Further describe the Error handling Identify the need for good documentation of the above Improve the Business Card Program!

3 CW-V1 SDD 0603 Variables A variable is a named piece of memory that holds information Think of it like a glass that can hold a measured amount of something The contents of the glass is called a data type The amount of contents would be its value

4 CW-V1 SDD 0604 Declaring Variables We declare variables to tell the program:  Their Name  What they will hold Dim Glass as Beer Glass = “Full” Declaration Keyword NameData type Initialise the variable Initial value: Full

5 CW-V1 SDD 0605 Declaring and Initialising Variables Dim PupilName as String Dim PupilGrade as Integer Name = “Hermione” Grade = 10 Variable names cannot contain spaces. Begin each word with a capital instead

6 CW-V1 SDD 0606 Variables Its value can be changed within the code Variables can be used to do mathematics It is better to use a variable than just type in a number  Makes code easier to read  Changes can be made more easily

7 CW-V1 SDD 0607 Data Types A variable can only be of one data type Some data types take up more memory than others Always use the least amount of memory possible to keep programs running efficiently Some data types have specialist functions

8 CW-V1 SDD 0608 The Money Trap The Currency data type cannot be formatted to display only two decimal places – this is a problem with VB6 To display money properly you must use Single Single variables may be formatted to display a set number of decimal places  Dim Cost as Single  Cost = 5.99 The pound sign will be added later when the value is displayed.

9 CW-V1 SDD 0609 Quiz Declare and Initialise variables for the following scenarios  A telephone number – 511 6000  The name of a course – A Level English  A student’s age – 17  Student’s date of birth – 01/02/1989  A bus fare - £3.50  Dinner tickets issued – Yes  Student Name – Tom Brown

10 CW-V1 SDD 06010 Quiz Dim TelNo as String Dim Course as String Dim Age as Integer Dim DateOfBirth as Date Dim BusFare as Single Dim DinnerTickets as Boolean Dim StudentName as String

11 CW-V1 SDD 06011 Quiz TelNo = “511 6000” Course = “A Level English” Age = “Integer” DateOfBirth = “01/02/1989” BusFare = 3.50 DinnerTickets = True Student Name = “Tom Brown”

12 CW-V1 SDD 06012 Constants Constants are like variables that cannot be changed once initialised Use them for values that will not change while the program is running, e.g. VAT Make things easier to remember e.g. the colour constant vbGreen replaces the value &H0080FF80& !! Their names usually begin with “c” e.g. cMin

13 CW-V1 SDD 06013 Calculations Use variables just like numbers! Dim FirstNo as Integer Dim SecondNo as Integer Dim Result as Integer FirstNo = 2 SecondNo = 5 FirstNo + SecondNo = 7 SecondNo – FirstNo = 3

14 CW-V1 SDD 06014 Comparisons Operators are used to compare two values x = yx is exactly the same as y OR make x the same as y x > yx is bigger than y x < yx is smaller than y x >= yx is bigger than or equal to y x <= yx is smaller than or equal to y x <> yx is not the same as y

15 CW-V1 SDD 06015 Quick Quiz Use comparison operators to write expressions for these scenarios  Phone bill is higher than gas bill  Pink is not equal to green  Electric bill is the same or less than gas bill  Starburst same as Opal Fruits

16 CW-V1 SDD 06016 Quick Quiz PhoneBill > GasBill Pink <> Green ElectricBill <= GasBill Starburst = OpalFruits

17 CW-V1 SDD 06017 Option Explicit Your New Best Friend Who has had problems with spelling mistakes in code? Put Option Explicit in the General Declarations of a form’s code  Keywords, variable and constant names are capitalised and corrected  Errors are highlighted when you run code

18 CW-V1 SDD 06018 Error Handling – Why Bother? Errors can make programs  Crash, freeze or end unexpectedly  Difficult to use  Give inaccurate information Try to think of errors likely to occur Test for errors Trap errors – tell the computer what to do if they occur, e.g. display a message It is never possible to trap all errors!

19

20 CW-V1 SDD 06020 Error Messages Good error messages should  Explain what the problem was Use Plain English Give examples if necessary  Why it occurred  How to fix it  What the user should do next  Give options as appropriate

21 CW-V1 SDD 06021 More about MsgBox Title Style (icon) Style (buttons) Message Put line breaks into your messages by using the constant vbctrlf e.g. MsgBox “This will be the top line” & vbcrlf & “and this will be the bottom line” Default choice Message boxes can be customised to be more user friendly


Download ppt "CW-V1 SDD 0601 Principals of Software Design and Development Variables Constants Data Types Error Handling Starter: BlockbustersBlockbusters."

Similar presentations


Ads by Google