understanding events

  • Thread starter Thread starter Erik Ekedahl
  • Start date Start date
E

Erik Ekedahl

I am a intermediate VB6 programmer moving to VB.NET using the book
"Programming Microsfot Visual Basic.net" (Microsoft Press)

I have understood so far what is going on but I am haveing a bit of
dificulty with events. My problem isn't syntax or howto or any of that, my
questions are:

What is the purpose of an event?
What is the "target" of the event (ie. who does what to whom)
Is there a difference between events in a class that you made and events in
built-in classes

Any help would be appreaceated.

Thank you.
Erik of Ekedahl
 
If you've been programming in VB6 you know all about events. Whenever you
do programmed something for a button click or a form load in VB6 those are
all events. In VB.NET they just let you see more of the details than in the
VB6 world.
What is the purpose of an event?
To notify a listener that something has happened
What is the "target" of the event (ie. who does what to whom)
You really have a producer (object that fired off the event, such as a
button) and a consumer (the object that is listening for the event, such as
a function in your personal class)
Is there a difference between events in a class that you made and events
in built-in classes
Nope

Chris
 
Erik,

Erik Ekedahl said:
I am a intermediate VB6 programmer moving to VB.NET using the book
"Programming Microsfot Visual Basic.net" (Microsoft Press)

I have understood so far what is going on but I am haveing a bit of
dificulty with events. My problem isn't syntax or howto or any of that, my
questions are:

What is the purpose of an event?

The purpose of an event is not notify event listeners. Classes, for
example, can subscribe to an event by providing an event handler and tieing
it to an object's event in order to get notified when the event is raised.
What is the "target" of the event (ie. who does what to whom)

An object raises an event if something is happening and other objects can
handle this event, which means that they can provide a method that is called
when the object's event is raised.
Is there a difference between events in a class that you made and events
in built-in classes

In general, there is no difference. There is a certain pattern that tells
how events should be implemented in reusable classes. You can find it in
the events documentation.

Events in VB.NET are very similar to those in VB6. I suggest to read the
documentation on events in Visual Basic .NET to understand the changes. If
you have any questions, feel free to ask them here.

Visual Basic Language Concepts -- Events and Delegates
<URL:http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconEventsDelegatesInheritance.asp>
 
Erik,

In past there where no events, everything was driven by the procedures, what
did mean that it was forever. Sent something to a screen, test if there
comes someting back.

Now a user can do everything with his mouse. So it is better to let the
program be driven by the events which are handled direct by the OS. A event
can be a mouseclick, an enter key etc.

You have to handle those events.

That is simple in VBNet.

When you have draged a button on your formlayout. Than you can click on that
and there is directly a click event as a sub created in the codepart. In
that you can set the code that you want to do because of that button click.

When you want other events you can look to the combobox in the left top of
your codepage and select that button. In the right combobox you can than
select the event, that is direct created.

There are more methods to trigger/catch an event. However I think this is
enough to start.

I hope this helps?

Cor
 
Thanks guys, Just needed that little bit to get me past the mental block!


Erik of Ekedahl
 

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

Back
Top