2 Different ways of handling Array Parameters

Method 1 – pass the whole array ByVal so that the procedure handles the entire array

Option Explicit
Private Sub CmdStart_Click()
'Set up variables
Dim multiple As Integer
Dim answers(12) As Integer 'Array of 12 numbers
'Get Multiplier from user
Call GetValue(multiple)
'Calculate Answers
Call CalcAnswer(answers(), multiple)
'Display table
Call DisplayTable(answers(), multiple)
End Sub


Private Sub GetValue(ByRef intvalue As Integer)
intvalue = InputBox("Please enter the value")
End Sub


Private Sub DisplayTable(ByRef answers() As Integer, ByVal multiple)
Dim counter As Integer
Dim Answer As Integer
For counter = 1 To 12
lstOutput.AddItem multiple & " X " & counter & " = " & answers(counter)
Next
End Sub


Private Sub CalcAnswer(ByRef answers() As Integer, ByVal multiple)
Dim counter As Integer
For counter = 1 To 12
answers(counter) = multiple * counter
Next
End Sub

Method 2 – Pass a single item of the array so that the procedure only handles integers

Option Explicit
Private Sub CmdStart_Click()
'Set up variables
Dim Multiple As Integer
Dim counter As Integer
Dim Answers(12) As Integer 'Array of 12 numbers
'Get Multiplier from user
Call GetValue(Multiple)
For counter = 1 To 12
'Calculate Answers
Call CalcAnswer(Answers(counter), Multiple, counter)
'Display table
Call DisplayTable(Answers(counter), Multiple, counter)
Next
End Sub


Private Sub GetValue(ByRef intvalue As Integer)
intvalue = InputBox("Please enter the value")
End Sub


Private Sub DisplayTable(ByVal Answer, ByVal Multiple, ByVal counter)
lstOutput.AddItem Multiple & " X " & counter & " = " & Answer
End Sub

Private Sub CalcAnswer(ByRef Answer As Integer, ByVal Multiple, ByVal counter)
Answer = Multiple * counter
End Sub

Both methods have their uses and differing programs call for differing strategies.

Parameter Passing with Arrays

The program you are about to see is known as a top down design this means that a problem is taken and broken down into smaller parts, worked out and executed.
You will see in this program that sub programs are used, these correspond to each level of the program this means that the program will run and only pick up on mistakes when it gets to that level. Also you could use breakpoints which will stop at the point you allocate the breakpoints too.
This type of program is known as a parameter this means that the pieces of information passes in and out of the program, to make the program work smoothly you must choose either byValue or byRefrence, by val means that the program does not change where as byref means the program will change.

Display the times table of the users choice
Option Explicit
Private sub CmdStart_Click()
‘Set up variables
Dim multiple As integer
‘Get Multiplier from user
Call GetValue(multiple)
‘Display table
Call DisplayTable(multiple)
End sub
Private sub GetValue(ByRef intvalue As Integer)
intvalue = InputBox(“Please enter the value”)
End sub
Private sub DisplayTable(ByVal multiple)
Dim Counter As Integer
Dim Answer As Integer

For counter = 1 to 12
Answer = multiple * counter
lstOutput.AddItem multiple & “X “ & Counter & “=” & Answer
Next
End Sub

Given you have typed in the correct coding the program should work however you need to look out for the byval and byref parts, in your second private sub because it is in the list box this will be what the answer is and multiple of your number, byVal is the correct one to use, however watch out if you put byRef in it’s place, this would keep the value as 0 and multiply by 0 and not the user’s input, this is because byVal stays the same meaning because the computers first number is 0 it will stay as 0, whereas byRef changes it and would therefore display the user’s input choice of multiple.

program testing and revision

Types of testing

Exceptional – values are not expected e.g “enter a number between 1 and 10” : -5,100,six

Extreme – allowed but at the very limits of the program
e.g “enter a number between 1 and 10” : 1,10

Normal: these are allowed inputs from the user e.g “enter a number between 1 and 10” : 3,8,5

testing table

e.g a quit button

button pushed|Expected|actual
yes | quit | quit
no |not quit|not quit

quick revison

documentation-userguide,technical guide

concatenation-joining strings

variable types:

string – numbers letters and other characters e.g 1,d,{

numeric – integer~whole number
single~decimal number
and boolean

Dim – set up variable

selection
simple – if one comparitor
complex – if more than one comparitor and a logic operator
ElseElif
Selectcase

iteration repition

In class we covered buffers sppoling and storage devices.
Buffering – a buffer is an area of the computers memory that is allocated to allow the transfer of data betweeen the computer and its peripherals. The buffer is mainly used if the fast part of a computer is comunicating with the slower devies that the computer uses, the buffer does this by storing the data temporarily untill it can be dealt with.
peripheral buffer – A printer operates at a much slower rate that what the cpmuter acts, so a buffer is used so taht the program can still run, instead of waiting for every character to be printed out, the data is sent to the printer by the operating system the usually deals with the buffers.
interface buffers – these are usually called Universal Asynchronous Reciever/Transmitter or UART, this is used to relieve the CPU of continuisly stopping what its doing.

Spooling – If large amounts of data are to be sent to one peripheral device, or if that device is shared between a network of computers tehn the preffered method is to spool, this compensates for the different speed of the proccesors and the peripheral. this allows output files to be queued from many programs and then sent to the printer one by one when the printer is ready.

Storage devices – one type of storage is magnetic storage, these can be found on hard disk drives, floppy disks, sip disks and magnetic tape.they are called magnetic storage because their surfaces are coated in a material that responds to a magnetic feild, these storage devices can be fixed or removable.
hard disks can be slit in to multiple levels with in the hard drive, but the disk its self is also split into different areas called tracks, sectors and cylinders.

Binary Numbers

Computers store all data as binary, numbers are easily stored this way.

Humans work with a base 10 numbering system (we have 10 fingers), however computers can only store data using electricity (on and off) which is base 2.

This article explains binary in a simple way

128  64  32  16  8  4  2  1 are the headings at the top of the binary numbers so 10001000 would be 128+8 which is 136

Practice here before attempting some bingo

For you exams you will be required to show the working for binary conversion, however, you can check this by using a calculator that has a binary function. The calculator below was found in a local pound shop, you can check if your calculator has binary by checking the buttons for BIN, OCT, DEC, HEX.

You can make a little Binary Calculator with the attached file. The photographs show it in action, simply fold the flaps to make the binary number and add the numbers shown. (teachers note that for 2’s complement just change +128 to -128)

Random List Generation and Array Handling

Well it looks like our Tuesday bloggers have let us down 🙁

Today’s lesson was to create a program to store 50 random number in an array and then to display that array in reverse. Once the task was given the pupils were asked to solve the problem. Most went straight to the computer and never thought about analysis or design, this led to confusion about the task and pupils were brought back and the task discussed again.

The Main steps were given to the pupil

  1. Set up variables
  2. Populate list with random numbers
  3. Create reverse list
  4. Display forward and reverse lists
  5. end program

After discussion we had the following refinements for step 2

  1. For 50 numbers
  2. Generate random whole number between 1 and 20
  3. Store number at next location in Array
  4. Next

In VB this is written as

For IntCounter = 1 to 50
IntNumber=int(rnd*20)+1
IntForward(Intcounter)=IntNumber
Next

Program Code for Times Table

Change the program code below so that the program performs the calculation in a separate procedure from the display.

Option Explicit
Private Sub CmdStart_Click()
'Set up variables
Dim multiple As Integer
'Get Multiplier from user
Call GetValue(multiple)
'Display table
Call DisplayTable(multiple)
End Sub


Private Sub GetValue(ByRef intvalue As Integer)
intvalue = InputBox("Please enter the value")
End Sub


Private Sub DisplayTable(ByVal multiple)
Dim Counter As Integer
Dim Answer As Integer
For Counter = 1 To 12
Answer = multiple * Counter
lstOutput.AddItem multiple & " X " & Counter & " = " & Answer
Next
End Sub

ADITDEM lesson!

We began the lesson discussing our coursework. We went over ADITEM.

Analysis:
is the understanding of the problem, which the systems analyst would perform. The systems analyst would use their techniques to gain information and produce a problem specification of basically what the customer wants the program to do.

Design:
The design in ADITDEM is a plan of the program will do. Two types of design are pseducode and structured diagrams. These designs involve steps taken to make the program. This makes it smaller and easier to understand.

To help us understand the concept of design we were given a task. We were given two pieces of paper, with which on one we had to make a shape/diagram e.g. paper aeroplane or oragami and on the other we had to write our steps taken to make this shape/diagram. We than were given a final piece of paper and swapped our steps with someone else. Each of us had then to use that person’s steps and make their shape. This task proved very difficult as hardly anyone’s shape was the same as the right one. This task told us that in design our pseducode and structured diagram had to be very detailed to work. We decided we need a way to help us design. Rules!
Our pseducode had to make rules. In our coursework the design stage is worth 6 marks. Our design must be understood by anyone to pass. It is worth looking over.

Implementation:
We use visual basic in class for implementation, however, there are a lot more. There are various, different languages and different sources.

Testing:

  • exceptional – values not expected, defensive program, assume the programmers don’t understand e.g. always check and verif
  • extreme – allowed but at limits, right on limit,  sensible data, e.g. you could enter the wrong PIN as long as it is in the rang
  • Normal – allowed e.g. enter a number between 1 and 5. The number 3 will be accepted.

TEST TABLE:
A test table will check the limits of the program e.g.

PRESSED          EXPECTED          ACTUAL
yes                          quit                        quit
no                       don’t quit           don’t quit

The program works, however, we cannot be sure of errors.

Software Development 2010 – where we are

You should find the powerpoint I used in class attached at the bottom of this entry.  Here are some of the example I used in class.

Squeakland – the home of etoys

Sugar on a stick – OLPC’s OS

Please see the PT ICM blog for minecraft

Software Development Catchup

The code we have created so far at the end of the period is given below, please see if you can finish it off.

Option Explicit
Private Sub CmdStart_Click()
‘Set up variables
Dim multiple As Integer
‘Get Multiplier from user
Call GetValue(multiple)
‘Display table
Call DisplayTable
End Sub
Private Sub GetValue(ByRef intvalue As Integer)
intvalue = InputBox(“Please enter the value”)
End Sub
Private Sub DisplayTable()
End Sub

Coltness High School

Report a Glow concern
Cookie policy  Privacy policy