What is the difference between a property a method and an
event? Give an example of each.
Answer Posted / chris barry
There is very little difference between VBA methods and
properties. A property is not analagous to a Java field, it
executes a class procedure just as a method does. The main
difference is that a property can be the left side of an
assignment.
Class methods are defined using the Function and Sub
keywords just as they would be used outside a class. User
defined properties use the Property key word together with
Get, Set or Let. A "Property Get" procedure seems almost
indistinguishable from a "Function" except that if there is
a corresponding "Property Let" then the compiler may check
that the type returned by "Get" is the same as the type
accepted by Let.
A "Property Let" procedure is defined as a normal function
with at least one argument, but it is called with one
argument fewer. The final argument takes its value from the
right side of the assignment. e.g.
Dim arr(4) As Integer
Property Let element(idx, val)
arr(idx) = val
End Property
could be called as:
ClassName.element(1) = 2
An event is something that happens asynchronously to the
main thread of the application, which can be linked to a
user-defined procedure (an event handler) which will be
invoked when the event occurs. In VBA at least, events are
most commonly generated by controls responding to user
actions.
| Is This Answer Correct ? | 4 Yes | 2 No |
Post New Answer View All Answers
How do I make a text box not beep but do something else when I hit the Enter key?
How would you create your application in DHTML?
To populate a single column value which dbcontrols you to use?
I have several megabytes of memory. Why do I get an "out of memory" error?
Is visual basic c#?
Types of ActiveX Components in VB?
What language does visual basic use?
What is the use of Active Control Property?
What is meant by building a recordset.
What is the need of tabindex property is label control.
Recordset object consists what?
How would you run your ActiveX Document Dll?
How many File System Controls are there Explain?
Explain the working of templates?
what are the Default cursor Type and LockEdit type in DAO?