P
paul
Q1/
a/ Describe 5 different data types used in Visual BASIC for
Applications. Each description should contain a definition of the data
type and an example of the type of data it can hold.
Q2/
a/ Demonstrate by example how a WHILE loop may be used. (10 marks)
b/ To demonstrating the use of a FOR loop write a short section of VBA
code to add up the first 10 elements in the array Data(). (15 marks)
Q3/
a/ The variable Colour is to be set using if statements depending upon
the values stored in the variables LandCover and Slope depending upon
the following rules:
· Colour is to be set to 1 if LandCover is less than 4 and slope is
less than 10
· Colour is to be set to 2 if LandCover is less than 10 but greater
than or equal to 4 and lope is less than 10
· Colour is to be set to 3 if Slope is greater than 10
· (13 marks)
b/ When passing arguments to a sub routine what do the terms passed by
address and passed by value mean? (5 marks)
c/ In order to georectify a point given as x,y coordinates the points
are represented by a vector the points are multiplied by a correction
matrix and a translation vector added to the result.
Write the VBA commands to place the two raw coordinates into the
array Coord(2) and the four correction parameters into the array
M(2,2) (7 marks)
Q4/
As part of a statistical analysis of temperature data a subroutine is
required to return the largest and smallest value of an array of a
given length.
If the calling line is:
CALL BigLittle(A, Length, Max, Min)
Write the required subroutine where A is the array of temperature
data, Length the number of temperature records to be searched, and Max
and Min the returned values. (25 marks)
Q5/
When using VBA with excel it is important to be able to read and
write to the excel spreadsheet. Write VBA commands to perform the
following tasks:
a/ Place in the variable X the number in the cell A4 (4 marks)
b/ Place in the cell A7 the text "Hello world" (4 marks)
c/ Place a message box on the screen giving the message contained in
the string variable, Prompt$ (4 marks)
d/ Read the area designated by the string variable Area$ into a one
dimensional array called Input() (4 marks)
e/ Read the 5 column and 3 row of the currently active spreadsheet
into the array element A(2,4) (4 marks)
f/ Read the value in the cell A9 from worksheet, sheet1 into the
variable, Step (5 marks)
Q6/
The VBA code in appendix A was written by a not very good programmer
to sort an array of numbers into ascending order.
a/ The programmer forgot to document the code to explain how it works.
Write an explanation of how the code works and explain exactly what it
is doing. (20 marks)
b/ The programmer also made an error in writing the program. Identify
this error (5 marks)
Appendix A Candidate number ________________
Sub test()
Dim data(10) As Single
Dim n As Integer
' data is acquired here
Call sort(data, n)
End Sub
Sub sort(A, length)
Dim I, J As Integer
Dim X As Single
For i = 1 To length
For j = 1 To (length - i)
If A(j) < A(j + 1) Then
x = A(j + 1)
A(j + 1) = A(j)
A(j) = x
End If
Next j
Next i
End Sub
a/ Describe 5 different data types used in Visual BASIC for
Applications. Each description should contain a definition of the data
type and an example of the type of data it can hold.
Q2/
a/ Demonstrate by example how a WHILE loop may be used. (10 marks)
b/ To demonstrating the use of a FOR loop write a short section of VBA
code to add up the first 10 elements in the array Data(). (15 marks)
Q3/
a/ The variable Colour is to be set using if statements depending upon
the values stored in the variables LandCover and Slope depending upon
the following rules:
· Colour is to be set to 1 if LandCover is less than 4 and slope is
less than 10
· Colour is to be set to 2 if LandCover is less than 10 but greater
than or equal to 4 and lope is less than 10
· Colour is to be set to 3 if Slope is greater than 10
· (13 marks)
b/ When passing arguments to a sub routine what do the terms passed by
address and passed by value mean? (5 marks)
c/ In order to georectify a point given as x,y coordinates the points
are represented by a vector the points are multiplied by a correction
matrix and a translation vector added to the result.
Write the VBA commands to place the two raw coordinates into the
array Coord(2) and the four correction parameters into the array
M(2,2) (7 marks)
Q4/
As part of a statistical analysis of temperature data a subroutine is
required to return the largest and smallest value of an array of a
given length.
If the calling line is:
CALL BigLittle(A, Length, Max, Min)
Write the required subroutine where A is the array of temperature
data, Length the number of temperature records to be searched, and Max
and Min the returned values. (25 marks)
Q5/
When using VBA with excel it is important to be able to read and
write to the excel spreadsheet. Write VBA commands to perform the
following tasks:
a/ Place in the variable X the number in the cell A4 (4 marks)
b/ Place in the cell A7 the text "Hello world" (4 marks)
c/ Place a message box on the screen giving the message contained in
the string variable, Prompt$ (4 marks)
d/ Read the area designated by the string variable Area$ into a one
dimensional array called Input() (4 marks)
e/ Read the 5 column and 3 row of the currently active spreadsheet
into the array element A(2,4) (4 marks)
f/ Read the value in the cell A9 from worksheet, sheet1 into the
variable, Step (5 marks)
Q6/
The VBA code in appendix A was written by a not very good programmer
to sort an array of numbers into ascending order.
a/ The programmer forgot to document the code to explain how it works.
Write an explanation of how the code works and explain exactly what it
is doing. (20 marks)
b/ The programmer also made an error in writing the program. Identify
this error (5 marks)
Appendix A Candidate number ________________
Sub test()
Dim data(10) As Single
Dim n As Integer
' data is acquired here
Call sort(data, n)
End Sub
Sub sort(A, length)
Dim I, J As Integer
Dim X As Single
For i = 1 To length
For j = 1 To (length - i)
If A(j) < A(j + 1) Then
x = A(j + 1)
A(j + 1) = A(j)
A(j) = x
End If
Next j
Next i
End Sub