In order to complete the first part of
c, you need to define the calculations in detail. This
means writing the all formulas down in the correct order. This will
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
a. Remember, for
a you decided on variable names when you were creating your
input, output and stored data tables.
Let's have an example:
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
In order to complete the second part of
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.
~~Example Form Load Sub Routine~~
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
~~Example Command Button Click Sub
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
~~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.
= num1 + num2
I can make this run from another sub routine by calling it, e.g.
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
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
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
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.
Choosing the correct sub routine
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?
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?
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?
I want to write code that changes the ?
when the user ticks a checkbox. Which sub routine should I write the code
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
Look at the each separate part and decide which
Basic sub routine you could use for each
different part. For examples, which sub routine could...
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,
amountLSeedPerSqMeter = 30
What about the other parts? Which sub routines
should you use for each part?