473,770 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a good way to write for events under VB?

Hello, experts:

I have a beginner's question. I would like to know if there is a sensible way
of writing event handlers under VB. For a Numeric Update control called
"nudSpin", this is apparently wrong:

Private Sub nudSpin_MouseUp () Handles nudSpin.MouseUp
' my code
End Sub

I get an error which says "Method 'nudSpin_MouseU p' cannot handle Event
'MouseUp' because they do not have the same signature."

OK, so what is this signature stuff about? If I create the method header the
old fashioned (VB6) way (by clicking on the control), I get:

Private Sub nudSpin_ValueCh anged(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles nudSpin.ValueCh anged
' place code here
End Sub

which is not what I want. I don't want a response to a changed value, I want a
response to someone releasing a mouse button while using the control. If I
changed the "Handles" modifier to "Handles nudSpin.MouseUp , I get the
signature error again.

I don't get this signature stuff. I am not using prorpietary controls, and
after reading warnings on this newsgroup, I have avoided ActiveX controls
(even though VB tells me they are available). The controls for this program
appear to be native to Microsoft VB.NET. Why can't I handle the events I want
to handle?

Thanks for any light you can shed on this

Paul King
Jun 23 '07 #1
5 1900
By looking around the documentation, it looks as though the initial problem
was overcome (by cutting and pasting), but not the larger problem of writing
methods generally.

It seems that fussing about "signatures " is Microsoft's way of saying the
parameters don't match the prototype. The word "signature" is too confusing,
since the same word is used in many other contexts (even in this newsgroup).
That is, nothing I was using needed any digital signing.

However, the question remains, if I need to write a specialised method, do I
need to memorise all possible syntaxes to all events for all controls, do I
cut and paste the syntax from the Help dialog, or is there something more
efficient? Obviously, clicking on the control doesn't give me the sensible
methods it used to give me.

Paul King

On Sat, 23 Jun 2007 15:18:13 -0400, Paul King <xo*****@hotmai l.comwrote:
>Hello, experts:

I have a beginner's question. I would like to know if there is a sensible way
of writing event handlers under VB. For a Numeric Update control called
"nudSpin", this is apparently wrong:

Private Sub nudSpin_MouseUp () Handles nudSpin.MouseUp
' my code
End Sub

I get an error which says "Method 'nudSpin_MouseU p' cannot handle Event
'MouseUp' because they do not have the same signature."

OK, so what is this signature stuff about? If I create the method header the
old fashioned (VB6) way (by clicking on the control), I get:

Private Sub nudSpin_ValueCh anged(ByVal sender As System.Object, ByVal e As
System.EventAr gs) Handles nudSpin.ValueCh anged
' place code here
End Sub

which is not what I want. I don't want a response to a changed value, I want a
response to someone releasing a mouse button while using the control. If I
changed the "Handles" modifier to "Handles nudSpin.MouseUp , I get the
signature error again.

I don't get this signature stuff. I am not using prorpietary controls, and
after reading warnings on this newsgroup, I have avoided ActiveX controls
(even though VB tells me they are available). The controls for this program
appear to be native to Microsoft VB.NET. Why can't I handle the events I want
to handle?

Thanks for any light you can shed on this

Paul King
Jun 23 '07 #2
Hello, experts:
>
I have a beginner's question. I would like to know if there is a
sensible way of writing event handlers under VB. For a Numeric Update
control called "nudSpin", this is apparently wrong:

Private Sub nudSpin_MouseUp () Handles nudSpin.MouseUp
' my code
End Sub
I get an error which says "Method 'nudSpin_MouseU p' cannot handle
Event 'MouseUp' because they do not have the same signature."

OK, so what is this signature stuff about?
Ok all events that are possible to code against have already been defined.
You do not get to say what that signature is. you must match by parameter
quantity and type.

If you wish to handle the Mouseup event then there are 2 ways to do it.

1.Define the instance of the control/class that you wish to handle events
for using the WithEvents keyword.
This will already have been done for you if you dragged the control onto
the form in the forst place.
Once done you can select the control from the dropdown in the top left of
the IDE and then select the event from the next dropdown in the top right.
This creates the Stub signature where you can fill out you handling code.

This can be done manually if you prefer. All you need to get right is the
params with their types and the handles keyword together with its Object.event
syntax at tyhe end.

2.Skip the "WithEvents " and "Handles" aspects but still code with the correct
params and their types. Then Attach the coded method to the object's event
using the AddHandler syntax
-------------------------------------------------------------
AddHandler <Object>.<Event >, Addressof <ProcName>
-------------------------------------------------------------

Hopefully this should set you on the right track.

If you need anything else... just ask :)

--
Rory
Jun 23 '07 #3

"Paul King" <xo*****@hotmai l.comwrote in message
news:3o******** *************** *********@4ax.c om...
Hello, experts:

I have a beginner's question. I would like to know if there is a sensible
way
of writing event handlers under VB. For a Numeric Update control called
"nudSpin", this is apparently wrong:

Private Sub nudSpin_MouseUp () Handles nudSpin.MouseUp
' my code
End Sub

I get an error which says "Method 'nudSpin_MouseU p' cannot handle Event
'MouseUp' because they do not have the same signature."

OK, so what is this signature stuff about? If I create the method header
the
old fashioned (VB6) way (by clicking on the control), I get:

Private Sub nudSpin_ValueCh anged(ByVal sender As System.Object, ByVal e
As
System.EventArg s) Handles nudSpin.ValueCh anged
' place code here
End Sub

which is not what I want. I don't want a response to a changed value, I
want a
response to someone releasing a mouse button while using the control. If I
changed the "Handles" modifier to "Handles nudSpin.MouseUp , I get the
signature error again.

I don't get this signature stuff. I am not using prorpietary controls, and
after reading warnings on this newsgroup, I have avoided ActiveX controls
(even though VB tells me they are available). The controls for this
program
appear to be native to Microsoft VB.NET. Why can't I handle the events I
want
to handle?

Thanks for any light you can shed on this

Paul King
The signature is the set of parameters sent by the assembly which is raising
the event. The first parameter is the control which is sending the event
and the second parameter depends on the type of event. For example a click
event for a button does not send any other info so the second parameter is
not used. For other events it will send information pertinant to the event.

When you double click a control in the designer you will get the "default"
event created. Just go to the list of controls in the dropdown at the top
of the source code, select the control you want to create an event for and
then from the dropdown beside it select the event you wish to create code
for. It is really not much different than VB6.

Lloyd Sheen

Jun 23 '07 #4
On Sat, 23 Jun 2007 19:36:20 +0000 (UTC), Rory Becker
<Ro********@new sgroup.nospamwr ote:
>If you wish to handle the Mouseup event then there are 2 ways to do it.

1.Define the instance of the control/class that you wish to handle events
for using the WithEvents keyword.
This will already have been done for you if you dragged the control onto
the form in the forst place.
Once done you can select the control from the dropdown in the top left of
the IDE and then select the event from the next dropdown in the top right.
This creates the Stub signature where you can fill out you handling code.
Thanks. I forgot about this from VB6.

Paul King
Jun 23 '07 #5
Paul King wrote:
I have a beginner's question. I would like to know if there is a sensible way
of writing event handlers under VB.
There is a standard convention for event handlers that permeates the
entire Framework - whether you regard this as "sensible" is another
matter entirely.
For a Numeric Update control called "nudSpin", this is apparently wrong:
Private Sub nudSpin_MouseUp () Handles nudSpin.MouseUp
The Event model changed /completely/ from VB6, which used what is now
referred to as an "auto-wireup" model. You /used/ to have ...

Sub nudSpin_ValueCh anged()

.... and /just/ because this method /happened/ to have the name of the
Control, followed by "_", followed by the name of the Event, the VB
compiler "hooked it up" to the ValueChanged event on the control,
nudSpin. This was the /only/ method that could handle that particular
event.

Now, in Brave New World.Net, we have the "new", "improved" event model,
using complicated signatures and the Handles keyword.

Sub nudSpin_ValueCh anged( _
ByVal sender as Object _
, ByVal e as EventArgs) _
Handles nudSpin.ValueCh anged

In every event handler, "sender" is the Control (or other object) that
raised the event, whatever that happened to be, and "e" is an
EventArgs-derived class that contains useful information about the event
(or EventArgs.Empty , if there's nothing useful to tell you).

However, in this mew way of thinking, you could just as well have ...

Sub fred66( _
ByVal sender as Object _
, ByVal e as EventArgs _
) Handles nudSpin1.ValueC hanged _
, nudSpin2.ValueC hanged _
, nudSpin3.ValueC hanged

.... one routine handling the ValueChanged event from three /different/
spin controls.
OK, so what is this signature stuff about?
Where we just used to have method Names, we now have Signatures - the
combination of the method Name and all its arguments. This is how
overloading works. Compare the signatures for the two Events:

Sub nudSpin_MouseUp ( sender as Object, e as MouseEventArgs )
Sub nudSpin_ValueCh anged( sender as Object, e as EventArgs )

Different signatures, different methods.
You can't "cross-wire" one event into a handler for another - the code
in the event handler will probably rely on certain properties being
present in the event arguments, "e", and if you send it the wrong Type
of event argument, that code will fail - the compiler is trying to
protect you from doing this when it complains about methods not being
able to handle one another's events.
I don't get this signature stuff.
It /does/ take a bit of getting used to...
Why can't I handle the events I want to handle?
You can; it's just a mite more fiddly to do that it used to be.

HTH,
Phill W.
Jun 25 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4207
by: David Thompson | last post by:
Looking for a book to help me develop a philosophy for building databases (particularly on MySQL). And then taking them from concept to construction. Something like.... Start by asking which queries you will be performing, then define all data needed for each of those queries, then progress to normalize this data, etc. Any Ideas....thanks...
19
3611
by: Raposa Velha | last post by:
Hello to all! Does any of you want to comment the approach I implement for instantiating a form? A description and an example follow. Cheers, RV jmclopesAThotmail.com replace the AT with the thing you know ;-) After discovering that access 2000 support form properties (I'm a
15
1404
by: John Salerno | last post by:
Ok, I've been reading an intro book to C# and I'm learning a lot of the basics. I can follow along with all the sample code and understand exactly what it's doing, but I know there's no way I'd be able to write the code myself. Also, it seems like every time I come here, or read info online, there is so much complicated stuff that I haven't even seen yet. Basically what I'm wanting to know is, how long do you expect it to take a...
2
1132
by: Anton Sommer | last post by:
Hello folks, what is the .NET framework snapin in IE good for? I mean in the Security settings of IE you can activate the execution of .NET framework components. How could a .NET developer execute such a Component? Thank you Anton
1
1177
by: Wootaek Choi | last post by:
Dear Sir, I create webform page that all html code is generated in code behind and sended to IE using Response.Write() like this, namespace localhost.XML { public class Encoding : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e)
1
930
by: jamie | last post by:
Happy holidays all. :) Okay now for the "more serious" stuff... Is there any good books for the .net classes? I am trying to find when piticular events are fired and from where. It is kinda anoying that it seams like guess work as to how the classes work to get the desired preformance and tricks out of the .net frame.
24
2291
by: Gaijinco | last post by:
I found one of that problems all of us have solve when they begin programming: given 3 numbers print the greater and the lesser one of the set. I was trying to remember the if-then-else structure when something hit me and I wrote: // Function returns the greater or lesser numbers of two given numbers, // specified by a flag: 1 for greater (default), 0 for lesser
7
7463
by: Rob R. Ainscough | last post by:
I'm having difficulty writing anything to the web servers event log from my web app located on that server. Putting this in my web apps web.config did NOT help - immediate causes and error in my web app before it displays the default page. <healthMonitoring> <rules> <add name="All Events" eventName="All Events" provider="EventLogProvider" profile="Critical" />
16
1466
by: AAaron123 | last post by:
I have a timer. At each tick, say 0.1 second, I write a file. If it takes more than 0.1 second to write the file the app will not work correctly. How can I tell in the tick event if the previous file finished writing so I can skip writing at that time? I write using the Bitmap.Save method.
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.