All posts by Mr Stratton

Computing teacher and a PT at Coltness High School.

Parameter Passing

We started of with SQA 2008 Q 1,3,&4 for a bit of revision.

Working with the program from last week we explored the concept and implementation of procedures (subprograms).

A procedure is a sub program with it own variables and routines, it is called from the main program with a procedural call and created by a procedural

A local variable is used within subprograms and is not passed back to the main program, this makes its domain the sub program.

A global variable is used when a piece of data needs to be seen in all sub programs, its domain is then the whole program. This is very bad programming form and should not be used.

Parameter passing allows the programmer to pass variables both in to and out of a sub program.

  • By value (ByVal) is used for input when the programmer does not want the subprogram to change the contents of the variable. The name comes from VB passing only the value of the variable.
  • By reference (ByRef)  is used for output when the programmer wants to get data from the subprogram.  The name comes from VB passing the memory reference of the variable and therefor allows the subprogram to directly edit it.

The picture above is the final program we created you can find the code Here

Homework for 13th Nov.

SQA 2007 Q17

17. John uses his digital camera to take photographs. It has a 512 Megabyte
memory card. His camera uses 16,777,216 colours and is set to a resolution of
3000 × 2000 pixels.
(a) (i) Calculate the file size of a single image. Your answer should be in
appropriate units. Show all working.
(ii) What is the maximum number of images of this size that can be
stored on John’s memory card?
(b) State two reasons why digital images are stored as JPEGs.
(c) He changes the setting in his camera to reduce the bit-depth.
Describe one effect that this will have.
(d) He connects his camera to his computer. One function of the interface is
the handling of status signals. Describe what is meant by the term “status
signals”.
(e) There are a large number of pictures on his hard disk. The combined size
of all of his photographs is 3 Gb.
He can use a solid-state storage device or Rewritable DVD to take all of his
photographs to his chemist shop for printing. Recommend one of these
devices and justify your choice.

Scanners

OK, I admit it I went on a little about this 🙂

Here is a good post on the working of a scanner and in researching it I found that the video (below) in question was correct for colour CCDs.

[kml_flashembed movie="http://www.youtube.com/v/ZTWQbeE82HU" width="425" height="344" allowfullscreen="true" fvars="fs=1" /]

We will look at CCDs in more detail in next weeks lesson.

Here is a take apart that shows a LED scanner in more detail 🙂

[kml_flashembed movie="http://www.youtube.com/v/AuMkpaenqm8" width="425" height="344" allowfullscreen="true" fvars="fs=1" /]

An excercise in fustration

I thought long and hard about today’s task, I set out to make a task that appeared easy to complete but without the correct design would prove to be frustrating.
The task below has been broken down so you need to follow it from start to finish and constantly revisit “finished” parts of the program, this is the iterative nature of programming.

1. Design and create a program that
a. Stores 20 class marks before displaying them and displaying the average to one decimal place.
b. Change the design and program to validate the marks (between 1 & 100) using the supplied function.
c. Change the design and program to also store the names of the students and then display the output in a two column report.

I’ll post the (1c) solution up tomorrow after class, the code for the function is after the break.

Continue reading An excercise in fustration

DIM

DIM is used to dimensionalise a variable, that is set memory aside for the variable to be stored. It is used thus

  • DIM Number1 as Integer
  • DIM Number2 as Integer

However this can be shortened to

  • DIM Number1, Number2 as Integer

In this case VB(Express Edition) sets number1 & number2 to integers. A more complex example can be seen below

  • DIM StrName as String
  • DIM Number1, Number2 as Integer

Becomes

  • DIM StrName as String, Number1, Number2 as Integer

You need to be careful that you get your syntax correct. It might be easier at the start to stick with the traditional(top) method.