Assignment 3 Guide
Implementation
Phase - Overview
These
notes give an overview of how to tackle your Assignment 3 program code.
Introduction
The
Assignment
The Whole Picture
Objectives
This guide will help
you to: -
·
think about how to go about implementing your program
·
describe how you could structure your program code
If you need to you should print out the
following two assignment documents.
Assignment Scenario
Assignment 3: Implementation
As with your previous assignments, Assignment3
is concerned with the
Lawnsword Garden Design Company.
The documentation you need to produce is listed below.
Assignment
3: Implementation |
Documentation required
1. Produce an annotated program listing which uses a consistent code
layout and clearly shows how you have used:
a) names and identifiers which are meaningful
b)
appropriate data types, including lengths and formats where applicable
c) modular program techniques
d) relevant programming constructs.
2.
Add detailed comments to your listing in order to describe and explain
the structure and workings of your program, and show how you have used a
consistent code structure. This will make your program listing easier to
read.
Include other evidence (such as annotated screen shots, manual
calculations, and witness statements) to show that:
e) the screens you have created are easy to use
f ) you have tested the program with the data
provided and also with test data that you have created
|
In this assignment you will use
your design documents from Assignment 2 to help
you create and
test the program. You will need to create your input and output forms,
then create the program code and then test your program.
Before diving in and creating program code it is always
best to have a good idea on how you are going to structure your program.
This means thinking about the inputs, stored data, outputs. For a VB
program the structure of your program will be also be influenced by user
events, (events like the user clicking a command buttons etc.) In
other words..
When thinking about how to structure your program code,
you need to think about sequences of events. The diagram below
illustrates the different parts of the program. Hover the mouse over
the link below it to see where each part could be
coded for in VB.
Starting with Step 1, the code for setting the values
of the stored data could be carried out inside the input forms Load
sub routine.
At Step 2, the
program needs to get the user's input. The code for getting the inputs
could be placed inside the Click sub routine for a Submit
button or equivalent.
At Step
3, the program needs to carry out the
calculations. The code for this could be placed inside a separate
sub routine - perhaps called something like calculate.
At Step
3, the program needs to display the
results. The code for this could be placed inside the output forms
Load
sub routine.
The diagram below shows the VB sub routines
in more detail.
 |
If you hover you mouse over a link or click on
it, you will see details on the sub routine and code that could be used
to carry out each part. |
Now it's your turn. Carry out the activity below. It will
help you to add all the forms and modules you will need to your project. It
will also help you create the basic code sub routines ready for later.
~~Activity~~
Activity A |
First, open up Visual Basic and start a new project.
Step 1 - Stored Data
-
Double-click the form, this will take you to the coding window.
Copy the following code..
Private Sub
Form_Load()
' code
goes here that
executes when the program first starts
'
e.g. set the values of the stored
data variables ready to use later on
End Sub
Step 2 - Get Inputs
-
Now add a command button to your form.
Name it cmdSubmit .
-
Double-click the command button, this will take you to the coding
window. Copy the following code..
Private Sub
cmdSubmit_Click()
' the user clicks the command button
'
code goes here that
gets the values from the
input textboxes
End Sub
Step 3
- Calculate
-
Now double-click the form, again Copy the following code..
Private Sub
calculate()
'code goes in here that does all the
calculations
End Sub
Step 4 - Display Results
-
Now add a second form to your project. You can do this by
clicking Project on the menu and then Add
Form .
-
Double-click the form, this will take you to the coding window.
Copy the following code..
Private Sub
Form_Load()
'code goes here that display the results
in labels
End Sub
Add Module for Declaring Variables
-
Finally, add a module to your project. You can do this by
clicking Project on the menu and then Add
Module . Copy the following code into the module..
'stored data variables
'input variables
'output data variables
You should end up with your project explorer showing 2 forms and a
module.

When you have finished by clicking the save
button.
VB will ask you to save both your forms, the module and the project.
Make sure you save them all to the same folder.
|
So far I have given you a general structure for your seed
calculation program. If you carried out Activity A
you will now have a basic structure from which you can start coding
properly. To help you along a little further, you can look at the same
coding structure here - I have
added a few lines of example code here and there.
~~Activity~~
Activity B |
It is important that you save your VB work properly. There are a
few important points to consider...
 |
Each separate form is saved into a separate form file. If you
lose your form file, you will have to create a new one.
There is no way around this. |
 |
Each separate module is saved into a module form file. If you
lose your module file, you will have to create a new one.
There is no way around this either.
|
 |
The project file just hold information about your project, such
as what forms files or module files VB should include in your
project. If you lose your project file, you can create a new
one. |
Try the following..
-
Go to the folder where you saved your VB work.
Double-click any form file. What happens?
-
Close VB and don't save anything if it asks. Now
double-click the project file. What happens?
-
Close VB and don't save anything if it asks. Move
one of your form files to a different folder, then we can pretend
you deleted it by mistake. Now double-click the project file.
What happens?
-
Close VB and don't save anything if it asks. Move
your form file back to where it was.
|
Your Task
Before going any further with the coding, you need to create
your GUI - your input and output
forms. This tutorial covers that.
fini
|