Software Development

  Assignment 3 Guide

Implementation Phase - Coding Step 1: Stored Data Variables

These notes guide you through assigning values to your stored data variables.

Introduction

Declare your Stored Data Variables

Assign Values to your Stored Data Variables


Introduction

Objectives

This guide  will help you to: -  

·  declare your stored data variables in VB

·  assign values to your stored data variables

If you need to you should print out the following two assignment documents.

Assignment Scenario

Assignment 3: Implementation


Declare your Stored Data Variables

Before we start, remind yourself of the basic program structure and the coding step you are currently on. You are on Step 1. Input Form - Set the Stored Data Values.

Before setting the values of your stored data variables, you need to declare them first.

In Assignment 2 part a you were asked to decide on formats and names for your variables. Here is a reminder...

Stored Data  Data Type VB Data Type Variable Name Min/Max Explanation
The amount of lawn seeds that cover 1 square meter

Whole number

integer

lawnSeedCoverage

The number must be larger than 0.  Max number of digits will be 3, so max number will be 999 This data type is likely to be a whole number  E.g. 30 grams
The amount of lawn seeds in a bag

Whole number

 

integer

lawnSeedinBag

The number must be larger than 0.  Max number of digits will be 3, so max number will be 999 This data type is likely to be a whole number  E.g. 1000 grams
etc... 

I started a table listing all of the stored data variables. Then I specified the data type as a single or integer depending on the data. Then I decided what the minimum and maximum number should be for each data type.  It is important to do this so that the number is not too big.

There should be a few more stored data items in your table.  I would say there should be at least 4. 

Your Task

Here are step by step instructions on how to declare your variables. You are going to declare all your variables inside a separate coding sheet called a module.

Module Coding Windows

  1. If you have not added a module to your project already, then on the VB menu, click Project, then Add Module. A new white coding window should appear. You need to save the separate module just like you save a form.  Here is a picture of my VB explorer window showing two forms (input and output) and my module.

     

  2. If you double-click the module you should get a white coding window. In the coding window, declare your variables like so...

~~Activity~~

Activity A

Declare all your stored data variables for your two lawns and two fields in your module. You should end up with about 4 stored data variables for both the lawns and the fields.

When you have declared your variables, click the save button to save your work. 


Assign Values to the Stored Data Variables

Your next task is to assign values to your stored data variables. The values need to be set before your program carries out any calculations, so the best time is probably right at the start when your form loads. You should already have this code inside your input form's coding window.  If not type it in now.

Step 1. Input Form - Set the Stored Data Values

Private Sub Form_Load()

        ' you could put code here that executes when the first program starts

        ' set the values of the stored data variables here

        ' ready to use later on

End Sub

Now you need to add code to the sub routine to set the stored data values.  I have added two lines of code to the sub routine, shown in bold below...

Private Sub Form_Load()

        ' you could put code here that executes when the first program starts

        ' set the values of the stored data variables here

        ' ready to use later on

        'example

        lawnSeedCoverage = 30

        lawnSeedinBag = 1000

            etc…..

End Sub

The names lawnSeedCoverage and lawnSeedinBag match the variables I declared in the module file. You must make sure you use the correct variable names and that the names match the names in your module file exactly.

~~Activity~~

Activity B

  1. Now finish the code and set the values of any other stored data variables you have. When you have finished, click the save button to save your work.

  2. Now click the run button just to see if VB accepts your code. It will complain if you have made a syntax error, (such as a spelling error, or have misnamed a variable.)

  3. At the top of all your forms you should make sure you have the word...

    Option Explicit

    This is an instruction to VB to check your code to see if you have declared all your variables.  VB looks through your code and if you have spelt one of your variables wrong it will tell you.

    To see what I mean, take one of your variables like lawnSeedCoverage and spell it wrong, i.e. lawnSeedCov

    Now run your program. VB will give an error message.


fini

 

 

   

  Unit Information

Assessment

Syllabus

Scheme of Work

Notes &Tutorials

Assignments

Quizzes

Books & Things

Links