assignment 1 visual basic calculator

27
Assignment 1 VB.NET

Upload: dnbsystems

Post on 18-Jul-2015

233 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Assignment 1 Visual Basic Calculator

Assignment 1 VB.NET

Page 2: Assignment 1 Visual Basic Calculator

Leon Allen

2 | P a g e

Contents P3 Interface Design ....................................................................................................................... 3

P4 Testable Spec........................................................................................................................... 4

P4 Test Plan.................................................................................................................................. 5

Test Log.................................................................................................................................... 5

Data Description ................................................................................................................... 5

Observed o/p ........................................................................................................................ 5

M3 Explanation of Errors ......................................................................................................... 17

P6 Evaluation ............................................................................................................................. 18

Analysis against original intentions .......................................................................................... 18

Positives ................................................................................................................................. 18

Negatives ............................................................................................................................... 18

Additional Features used ......................................................................................................... 18

Future Improvements ............................................................................................................. 18

Conclusion............................................................................................................................. 19

P5 Help Feature ...................................................................................................................... 20

M2 Data Validation ................................................................................................................. 21

D2 Error Handling ................................................................................................................... 21

Program Code ............................................................................................................................ 22

Page 3: Assignment 1 Visual Basic Calculator

Leon Allen

3 | P a g e

P3 Interface Design

My calculator is designed to look similar to an iPhone calculator with a difference.

The picture above shows all three sections of my calculator and the picture below

shows the program open with no calculators open

My times table and conversion calculators lay over the top of the normal calculator

and using the menu you can select which calculator to open.

Page 4: Assignment 1 Visual Basic Calculator

Leon Allen

4 | P a g e

P4 Testable Spec

Does the program start.

Will the menu options work to;

- Open the calculator

- Open the time table calculator

- Open the conversion calculator

- Close the calculator

- Close the times table calculator

- Close the conversion calculator

- Exit the application

- Does the help button open the help window

Normal Calculator;

- Do all the calculator buttons work,

- Will it allow user input

- Will it add numbers together

- Will it times numbers together

- Will it minus numbers

- Will it divide numbers

- Can user enter text into the calculator

Times table calculator

- Do all the buttons work

- Will it let you enter text

- Will it let you enter a number In startNum < 1 Or endNum > 50 Or multiNum > 100

- Does above work when you calculate or give you the error message

- Does the Ac button work

- Are results displayed correctly in results window

Conversion Calculator

- Can user input number to be converted

- Does the AC button work

- Do all the conversion buttons work

- Can user input qwerty

Page 5: Assignment 1 Visual Basic Calculator

P4 Test Plan

Test Log. Date:

Program Name: Calculator program Version: 1

Author: L. Allen Tested By:

Test No. Test Data

Data Description

Expected o/p Observed o/p Success /

Fail

Comments / Suggestions

Category of Test e.g. Normal/Extreme/Erroneous Data

1 Open the calculator

Menu should open the

calculator

Success Going into the open option and

clicking the calculator as shown

works menu selection in picture

for illustration purposes.

Page 6: Assignment 1 Visual Basic Calculator

Leon Allen

6 | P a g e

2 Open the time table

calculator

Menu should open the

Times table calculator

Success Going into the open option and

clicking the times table as

shown works menu selection in

picture for illustration

purposes.

3 Open the conversion

calculator

Menu should open the

conversion calculator

Success

Page 7: Assignment 1 Visual Basic Calculator

Leon Allen

7 | P a g e

4 Close the calculator Menu should close the

calculator

Success

5 Close the times table

calculator

Menu should close the

times table calculator

Success

Page 8: Assignment 1 Visual Basic Calculator

Leon Allen

8 | P a g e

6 Close the conversion

calculator

Menu should close the

conversion calculator

Success

7 Exit the application Application should

close

Program exits and closes the application. Success

8 Does the help button open

the help window

Help window should

open

Success

Page 9: Assignment 1 Visual Basic Calculator

Leon Allen

9 | P a g e

9 Do all the calculator

buttons work

All the buttons should

work when clicked

Success All the buttons work as

expected when clicked with

mouse

10 Will it allow user input Yes but not via typing

on keyboard to help

reduce errors

Success Yes the user can input numbers

via pressing the buttons on

screen

Page 10: Assignment 1 Visual Basic Calculator

Leon Allen

10 | P a g e

11 Will it add numbers

together

Should add numbers

together

Success For this test I enters 1+1= and

the answer was 2 (as shown)

I tried adding ; 1+1, 2+2, 3+3,

4+4, 5+5, 6+6, 7+7,8+8, 9+9

12 Will it times numbers

together

Should times numbers

together

Success For this test I enters 1*2= and

the answer was 2 (as shown)

I tried adding ; 1*2, 2*2, 3*3,

4*4, 5*5, 6*6, 7*7,8*8, 9*9

Page 11: Assignment 1 Visual Basic Calculator

Leon Allen

11 | P a g e

13 Will it minus numbers Should minus the

numbers

Success For this test I enters 3-1= and

the answer was 2 (as shown)

I tried adding ; 3-1, 4-1, 5-1, 6-

1, 7-1, 8-1, 9-1

14 Will it divide numbers Should divide the

numbers

Success For this test I enters 4/2= and

the answer was 2 (as shown)

I tried adding ; 3/1, 4/2, 5/3,

6/2, 7/2, 8/2, 9/1

15 Can user enter text into

the calculator

No user cannot enter

qwerty into the

calculator due to

textbox being disabled

Success

Page 12: Assignment 1 Visual Basic Calculator

Leon Allen

12 | P a g e

16 Do all the buttons work Yes the two buttons

should work to

calculate and clear

User should also be

able to input numbers

in the 3 text boxes

Success

17 Will it let you enter text Yes it will let you enter

qwerty in the boxes

but will show the error

message when you

click the calculate

button

Success As shown in the picture you can

enter qwerty into the text

boxes when calculate is pressed

it shows the error message

Page 13: Assignment 1 Visual Basic Calculator

Leon Allen

13 | P a g e

18 Will it let you enter a

number In startNum < 1

Or endNum > 50 Or

multiNum > 100

Yes you can input

above these values but

once calculate is

pressed the error

message shows

success As shown in the picture you can

enter values greater into the

boxes but when calculate is

pressed it shows the error

message

19 Does above work when

you calculate or give you

the error message

Yes – shows an error

message

success As shown in the picture the

error message

Page 14: Assignment 1 Visual Basic Calculator

Leon Allen

14 | P a g e

20 Does the Ac button work Yes when clicked

should clear the text

boxes

success

21 Are results displayed

correctly in results window

Yes the results should

display correctly in the

results box

Success

Page 15: Assignment 1 Visual Basic Calculator

Leon Allen

15 | P a g e

22 Can user input number to

be converted

Yes

Success

23 Does the AC button work Yes

Success

Page 16: Assignment 1 Visual Basic Calculator

Leon Allen

16 | P a g e

24 Do all the conversion

buttons work

Yes

Success

25 Can user input qwerty Yes

Success Yes the user can input letters

but when a conversion button

is pressed an error message is

displayed

Page 17: Assignment 1 Visual Basic Calculator

M3 Explanation of Errors

To begin with I had a error with times table part of the program (see code below),

this turned out to be because the try statement was correct but in should have been

after the after the times table calculation and not before it.

Try If startNum < 1 Or endNum > 50 Or multiNum > 100 Then MsgBox("You can not enter those numbers sorry for your incovience ", MsgBoxStyle.Exclamation) Else startNum = startNumber.Text endNum = endNumber.Text multiNum = mutliplier.Text For i = startNum To endNum answer = i * multiNum

Apart from the above error due to the coding the rest of my tests were a success.

Page 18: Assignment 1 Visual Basic Calculator

Leon Allen

18 | P a g e

P6 Evaluation

Analysis against original intentions

The original intentions for my calculator were for it to make calculations, be able to

also make multiplications using times tables and display the results in a table. I also

wanted it to be able to convert units of measurements easily from miles to Km, Km to

miles and lbs to Kgs and Kgs to lbs. I also wanted the calculators to be easy to use.

If the user who is using the calculator gets stuck at any point then they can use the

menu to access a user guide on the calculator they are using.

Positives

My designs were easy to use and to create.

The main menu is integrated into the program which allows the user to

change which calculator they are using.

There is a help menu if the user needs help.

There is an exit button so the user can exit the program using the menu.

Not all of the calculators display at the same time so the user can open the

one they wish to use or switch between calculators easily.

The user won’t get confused about which calculator they are using.

Negatives

The user has to enter the menu each time they want to change calculators

The user can still input text into the conversion calculator and times table

calculator

The user may get annoyed at the limits on the times table calculator

The user could get annoyed at the error messages.

Additional Features used

Additional features I have used;

I used a menu system. I decided to do this to help the user so they can

navigate around the program

I integrated a help menu into the program so the user can access help if they

need too.

Future Improvements

Some future improvements I could use;

I think a labelling the different calculators so the user can easily see which

what calculator they are using. This can be done by adding a label field to

each calculator group box so you can clearly see which calculator you are

using when you open one of them.

I think users could benefit from a more detailed help section. This can be

done adding more detail to the help section by adding a more detailed

explanation of the errors and how to use the program in more detail.

Page 19: Assignment 1 Visual Basic Calculator

Leon Allen

19 | P a g e

Improving the error messages with more detail so the user can see more

easily what they have done wrong to see an error message. This can be

done by adding more text to the messages to explain what the errors are and

what has caused them.

Conclusion

I believe that the programming the calculator went well. I’m happy with finished

product and that it meets the requirements detailed in the brief. The best part and

by far easiest part of the program was designing how I wanted the program to look

and then placing the design onto the program. I thought this was the easy part of

making the program because you can just drag the items you want to use on the

form.

The next part was making the menu which was easy to do as well. Next on the list

was coding program, I feel this was the hardest part of making the finished

program. This was because I made some errors in the programming and it took a

while to fix them using the debugging tool to see exactly where the errors were.

Once the programming was finished and error free and all the menu options worked

the final part of coding was the error messages to stop the program from crashing

when the user input invalid data.

Page 20: Assignment 1 Visual Basic Calculator

Leon Allen

20 | P a g e

P5 Help Feature

Page 21: Assignment 1 Visual Basic Calculator

Leon Allen

21 | P a g e

M2 Data Validation

I have Implemented data validation on my calculator program for the user input to

help to prevent people entering the wrong type of information. In order to this I have used different types of validation on the different parts of the calculator which are shown below.

Allowed character checks - This is part of the try/catch code. It Checks that only

expected characters have been input into the field. For example all three calculators are numeric so even though it will let you enter letters when you try to progress to the next part you will receive an error message saying that the data input was

incorrect.

Limit check The Times table has a limit check for the data being input, this tells the

calculator that in this case the data checked has a limit so if the startNum <1, the endNum is >50 or the mutliNum is >100 then the user gets the error message. (code

below)

If startNum < 1 Or endNum > 50 Or multiNum > 100 Then MsgBox("You can’t enter those numbers sorry for your incovience", MsgBoxStyle.Exclamation)

D2 Error Handling

Error handling refers to the programming practice of anticipating and coding for

errors that may arise when your program runs. Normally if an error occurs the

program will crash so to stop this from happening I have used the try/catch code to

help prevent the program from crashing and providing the user with an error

message. An example is shown below;

Try

TextBox1.Text = TextBox1.Text + "0" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation)

End Try

Page 22: Assignment 1 Visual Basic Calculator

Leon Allen

22 | P a g e

Program Code

'Leon Allen. 30/05/2014. my vb calculator' 'Group box 1 - the calculator' Public Class Form1 Dim FirstNumber As Single Dim SecondNumber As Single Dim AnswerNumber As Single Dim Process As String Dim startNum As Integer Dim endNum As Integer Dim multiNum As Integer Dim i As Integer Dim answer As Integer Private Property GroupBox1_Enter As Boolean Private Property GroupBox2_Enter As Boolean Private Property GroupBox3_Enter As Boolean 'code for Calculator AC button' Private Sub ButtonAC_Click(sender As Object, e As EventArgs) Handles ButtonAC.Click TextBox1.Text = "" 'Enable to clear End Sub 'code for button 1' Private Sub Btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn1.Click Try TextBox1.Text = TextBox1.Text + "1" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button 2' Private Sub Btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn2.Click Try TextBox1.Text = TextBox1.Text + "2" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button 3' Private Sub Btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn3.Click Try TextBox1.Text = TextBox1.Text + "3" Catch

Page 23: Assignment 1 Visual Basic Calculator

Leon Allen

23 | P a g e

MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button 4' Private Sub Btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn4.Click Try TextBox1.Text = TextBox1.Text + "4" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button 5' Private Sub Btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn5.Click Try TextBox1.Text = TextBox1.Text + "5" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button 6' Private Sub Btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn6.Click Try TextBox1.Text = TextBox1.Text + "6" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button 7' Private Sub Btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn7.Click Try TextBox1.Text = TextBox1.Text + "7" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button 8' Private Sub Btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn8.Click Try TextBox1.Text = TextBox1.Text + "8" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button 9' Private Sub Btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn9.Click

Page 24: Assignment 1 Visual Basic Calculator

Leon Allen

24 | P a g e

Try TextBox1.Text = TextBox1.Text + "9" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button 0' Private Sub Btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn0.Click Try TextBox1.Text = TextBox1.Text + "0" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button decimal point' Private Sub Btnpoint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnpoint.Click Try TextBox1.Text = TextBox1.Text & "." Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button plus' Private Sub Btnplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnplus.Click Try FirstNumber = Val(TextBox1.Text) TextBox1.Text = "" Process = "+" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button minus' Private Sub Btnminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnminus.Click Try FirstNumber = Val(TextBox1.Text) TextBox1.Text = "" Process = "-" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button times' Private Sub Btntimes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btntimes.Click Try FirstNumber = Val(TextBox1.Text)

Page 25: Assignment 1 Visual Basic Calculator

Leon Allen

25 | P a g e

TextBox1.Text = "" Process = "*" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for button divide' Private Sub Btndiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btndiv.Click Try FirstNumber = TextBox1.Text TextBox1.Text = "" Process = "/" Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'code for equals button ' Private Sub Btnequals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnequals.Click Try SecondNumber = TextBox1.Text If Process = "+" Then AnswerNumber = FirstNumber + SecondNumber End If If Process = "-" Then AnswerNumber = FirstNumber - SecondNumber End If If Process = "*" Then AnswerNumber = FirstNumber * SecondNumber End If If Process = "/" Then AnswerNumber = FirstNumber / SecondNumber End If TextBox1.Text = AnswerNumber Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'Group box 2- times table calculator' Private Sub Calculate_Click(sender As Object, e As EventArgs) Handles Calculate.Click Try If startNum < 1 Or endNum > 50 Or multiNum > 100 Then MsgBox("You can not enter those numbers sorry for your incovience ", MsgBoxStyle.Exclamation) Else startNum = startNumber.Text endNum = endNumber.Text multiNum = mutliplier.Text For i = startNum To endNum answer = i * multiNum

Page 26: Assignment 1 Visual Basic Calculator

Leon Allen

26 | P a g e

bResults.Items.Add(i & " Times " & multiNum & " = " & answer) Next i End If Catch MsgBox("An input error has occured. please enter the correct fromat ", MsgBoxStyle.Exclamation) End Try End Sub 'Group box 2 - AC Button for times table' Private Sub TAC_Click(sender As Object, e As EventArgs) Handles TAC.Click startNumber.Text = "" 'Enable to clear endNumber.Text = "" 'Enable to clear mutliplier.Text = "" 'Enable to clear bResults.Items.Clear() End Sub 'GroupBox 3 - Conversion Calculator' 'Conversion to lb's button' Private Sub btnPounds_Click(sender As Object, e As EventArgs) Handles btnPounds.Click Try OutputText.Text = 0.453 * InputText.Text Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'Groupbox 3 - conversion to kg button' Private Sub btnKg_Click(sender As Object, e As EventArgs) Handles BtnKG.Click Try OutputText.Text = 2.205 * InputText.Text Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'Groupbox 3 - conversion to Miles button' Private Sub btnMiles_Click(sender As Object, e As EventArgs) Handles BtnMiles.Click Try OutputText.Text = 1.609 * InputText.Text Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'Groupbox 3 - conversion to Km button' Private Sub btnKm_Click(sender As Object, e As EventArgs) Handles BtnKm.Click Try OutputText.Text = 0.621 * InputText.Text Catch MsgBox("An input error occured please try again. ", MsgBoxStyle.Exclamation) End Try End Sub 'Groupbox 3 - conversion clear button'

Page 27: Assignment 1 Visual Basic Calculator

Leon Allen

27 | P a g e

Private Sub CAC_Click(sender As Object, e As EventArgs) Handles CAC.Click InputText.Text = "" 'Enable to clear OutputText.Text = "" 'Enable to clear End Sub 'Main Menu - Open calculator' Private Sub CalculatorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CalculatorToolStripMenuItem.Click GroupBox1.Visible = True GroupBox2.Visible = False GroupBox3.Visible = False End Sub 'Main Menu - Times table calculator' Private Sub TimesTableToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TimesTableToolStripMenuItem.Click GroupBox1.Visible = False GroupBox2.Visible = True GroupBox3.Visible = False End Sub 'Main Menu - Opens conversion calculator' Private Sub ConversonChartToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ConversonChartToolStripMenuItem.Click GroupBox1.Visible = False GroupBox2.Visible = False GroupBox3.Visible = True End Sub 'Main Menu - Closes open programs' Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click GroupBox1.Visible = False GroupBox2.Visible = False GroupBox3.Visible = False End Sub 'Main Menu - Exit application' Private Sub ExitToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem1.Click Application.Exit() End Sub 'Help menu code' Private Sub HelpToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles HelpToolStripMenuItem.Click MsgBox("Hello and welcome to the help guide." & vbCrLf & "The first part of this program is the basic calculator - this can be used for making caculations" & vbCrLf & "The Times Table calculator - This is used for showing times tables " & vbCrLf & "The Conversion Calculator - This is used to convert either lb to Kg, Kg to lb's, or Miles to Km's, Km's to Miles" & vbCrLf & "" & vbCrLf & "If you recieve an error message then you have input a invalid key, if this is the case clear the calculations screens using the clear buttons and try inputing the values again", MsgBoxStyle.Information) End Sub End Class