# Software Development

## Assignment 2 Guide

Introduction

### Introduction

Objectives

·   Define the calculations in detail - including writing them in VB form

·   Define how you are going to structure and control the processing

You should print out the following two assignment documents.

Assignment Scenario

Assignment 2: Designing the Program

### Task c - First Part:  Produce Detailed Calculations

In order to complete the first part of `Assignment` `2` `Task` `c`, you need to define the calculations in detail.  This means writing the all formulas down in the correct order.  This will include...

• the formulas for calculating the areas

• the formulas for calculating the amount of seeds

• the formulas for calculating the number of bags

Once you have written the formulas down, you will then have to write equivalent formulas using the Visual Basic variable names you decided on in `Task` `a`. Remember, for `Task` `a` you decided on variable names when you were creating your input, output and stored data tables.

Let's have an example:

 Area Formulas Formula 1        Area of Rectangular Lawn  = Length * Width Visual Basic Formula 1```  rectLawnArea = rectLawnLength * rectLawnWidth``` Formula 2      Area of Circular Lawn  = 22 / 7 * Radius * Radius Visual Basic Formula 2```  circLawnArea = 22 / 7 * circLawnRadius * circLawnRadius ``` `  ``etc.....`

Of course, this needs finishing. You will also need the formulas for the amounts and the number of bags. Remember to use the variable names you decided upon in `Task` `a`.

Now it's your turn to produce detailed calculations.  You can download this Word document with the table drawn in ready for you.  You will have to add extra row and type in the formulas yourself of course. Alternatively, you may wish to write all the formulas first in plain words and then rewrite the formulas using variables afterward.  If so, you can download this Word document instead.

Assignment 2: Designing the Program

Task c: The calculations in detail

Here you should include a table showing all your formulas

### Task c - Second Part:  Define the Structure of your Processes

In order to complete the second part of `Assignment` `2` `Task` `c`, you need to explain how you are going to structure and control the processing in your program.

This means you will need to decide how you are going to structure your Visual Basic code.  Because events like a form loading, a user clicking a button, occur at different times when a program is running, when writing code, it is important to put different blocks of code in the right place.  You can write your code inside structures called sub routines.

Here is an example of a simple sub routine that sets the background colour of a form to red when the form loads up for the first time.

Form1.color = vbRed

End Sub

~~Example Command Button Click Sub Routine~~

Here is an example of another simple sub routine that hides one forms and shows another form when the user clicks a command button called `cmdNext`.

Private Sub cmdNext_Click()

Form1.Hide

Form2.Show

End Sub

~~Example Custom Sub Routine~~

I can create my own special sub routines easily enough and make them run by calling them from other sub routines.  Here is a custom sub routine that adds two numbers together.

num3 = num1 + num2

End Sub

I can make this run from another sub routine by calling it, e.g.

End Sub

Now when the form loads, the form load sub routine calls the add sub routine and makes it run.

Since you can place different code in different sub routines, it is a good idea to know when different sub routines will run. then you will understand which sub routines to use in your program.

~~Description of Some Important Sub Routines~~

• Form_Load  - This sub routine runs as soon as the form loads and before it appears.  It is a good idea to place code in here that you want to run before the form is shown.  Each form has it's own form load sub routine.

• CommandButton_Click - This sub routine runs when a button is clicked.  You would put code in here that you want to run when the user clicks a command button.

• CheckBox_Click - This sub routine runs when a checkbox is clicked.  You would put code in here that you want to run when the user ticks or unticks a checkbox.

~~Activity~~

 Activity A Choosing the correct sub routine Question 1 I want to write code that sets a form's background colour to blue and clears all the textboxes ready for user input. I want his to happen before the form displays itself to the user, when the program starts. Which sub routine should I write the code inside?      Form_Load CommandButton_Click CheckBox_Click Custom Sub Routine Question 2 I want to write code that hides one form and displays another form when the user clicks a command button. Which sub routine should I write the code inside?      Form_Load CommandButton_Click CheckBox_Click Custom Sub Routine Question 3 I want to write calculation code for subtracting two numbers. I want to be able to call this calculation code from another sub routine Which sub routine should I write the code inside?      Form_Load CommandButton_Click CheckBox_Click Custom Sub Routine Question 4 I want to write code that changes the ? when the user ticks a checkbox. Which sub routine should I write the code inside?      Form_Load CommandButton_Click CheckBox_Click Custom Sub Routine

Now its time for you to decide how you are going to structure your program.  First, remind yourself of the overall structure of your program by looking at the diagram below.  You should have produced a more detailed and complete diagram for `Assignment` `1` `Task` `h`.

Look at the each separate part and decide which ``` Visual``` `Basic` sub routine you could use for each different part.  For examples, which sub routine could...

• set all the stored data values

• get the inputs

• carry out the calculations

• display the outputs

To help you with this, I have started a diagram below that shows which sub routine I am going to use for each part. So far, I have only chosen one sub routine for the stored data part. It is up to you to finish the rest.

Notice how I have chosen a sub routine for setting the stored data values. I decided I wanted to set the values of the stored data just as the program starts, as soon as the form loads, e.g.

amountLSeedPerSqMeter = 30

amountHMSeedPerSqMeter = 20

etc.

End Sub

What about the other parts?  Which sub routines should you use for each part?

Now it's your turn to produce a diagram that shows which sub routines you are going to use for the inputs, outputs, etc.