Can anyone help me answer these questions or nay of them as im struggling with understanding the VBA

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
 
D

Don Guillett

We do NOT do homework, especially pro bono.

--
Don Guillett
SalesAid Software
(e-mail address removed)

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
 
H

Helmut Weber

Hi Paul,

others answering the questions put to you
won't get you far, hopefully.

Your teacher didn't declare variables properly.
First, there is no use of integer,
for performance issues, in theory.
Use long.
Second, your teacher declared I as variant.
No good as well.

Your teacher wouldn't like to hear that.

What he or she would like to see is
something wrong in the bubble-sorting.

Good luck.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
P

paul

thanks very much for that, thats very helpful, could you possibly
explain why you need to declare variables and why I as a variant is
not good?

thanks again
 
H

Helmut Weber

Hi Paul
thanks very much for that, thats very helpful, could you possibly
explain why you need to declare variables and why I as a variant is
not good?

good questions, it's only that good answers are hard to find.

I don't know, maybe compare programming
with what you find in a construction kit for a car.

In the instructions you may find a list of all the parts:

nuts, screws, washers, wheels, axes,
something ' variant! ?

Still better would be,
nuts(16) , screws(16), washers(32),
wheels(4), axes(2),
something ' variant! ?

All that corresponds to declarations.

So you know what you have to deal with,
except the variant.
Otherwise, it's just stumbling in the dark.

In addition, for the sorting,
see help for "option base".

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top