|
-
Sep 23rd, 2004, 05:29 AM
#1
Thread Starter
Frenzied Member
Order of Sequence for Multiple Subroutines Handling the Same Event
I have a couple of subroutines that all handle the same event for many controls. Is it possible to predict or force the way the program accesses each subroutine when the event is fired?
i.e.
VB Code:
Private Sub Sub1(...) Handles Button1.Click
...
Private Sub Sub2(...) Handles Button1.Click
...
Private Sub Sub3(...) Handles Button1.Click
...
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Sep 23rd, 2004, 12:23 PM
#2
Frenzied Member
Ideas:
Pardon my ignorance (hey, I'm just a newbie!), but why do you require 3 different subroutines to handle the same event?
I know that there are things like keypress that pass through several different handlers, but these are classified as different events (key down, key up, etc.).
Use 1 handler and conditionally call your 3 subroutines from the handler in whatever order you want. ???
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Sep 24th, 2004, 02:37 AM
#3
Thread Starter
Frenzied Member
Dunno, I just wanted it done that way for some reason, I know I can do it by calling different subs, maybe because not every sub handles the same controls, some are common between them, but some have their own unique controls also.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Sep 24th, 2004, 03:27 AM
#4
Hyperactive Member
I just wanted it done that way for some reason,
hey! just for curious thing. what are you trying to achieve anyway, i mean you said that every sub have their own unique controls but how do you like to achieve it.
-
Sep 27th, 2004, 07:40 AM
#5
Thread Starter
Frenzied Member
Well, I did put it in one subroutine, but it still doesn't answer the question. You must be able to do it, otherwise, why would it be possible?
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Sep 27th, 2004, 07:45 AM
#6
It works in the order that the event handlers are added to the event. If you want to control the order, I would add the handlers manually using AddHandler.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Sep 27th, 2004, 08:04 AM
#7
Fanatic Member
code
VB Code:
Dim b As New Button()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
b.Text = "Button1"
AddHandler b.Click, AddressOf b_click1 ' first
AddHandler b.Click, AddressOf b_click2 ' second
AddHandler b.Click, AddressOf b_click3 ' third
Me.Controls.Add(b)
End Sub
Sub b_click1(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("fist")
End Sub
Sub b_click2(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("second")
End Sub
Sub b_click3(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("third")
End Sub
-
Sep 27th, 2004, 08:11 AM
#8
PowerPoster
Originally posted by Ideas Man
Well, I did put it in one subroutine, but it still doesn't answer the question. You must be able to do it, otherwise, why would it be possible?
No positive answer but the firing order is NOT linked to any of:
1. The name of the event e.g. Button1_Click is not necessarily fired before Button2_Click or Button11_Click. Although altering the name of the event CAN alter the order of firing.
2. The order in which the events appear in the code.
3. The order in which the events were added to the code.
MSDN offers no advice on this.
It is possible because it cannot be diferentiated from having multiple handlers, but it is totally unnecessary, as other postings have pointed out.
Please note; The use of capitals is not intended as a "Shout" but in it's normal English usage, i.e. to draw attention to the meaning.
Last edited by taxes; Sep 27th, 2004 at 08:28 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Sep 28th, 2004, 03:38 AM
#9
Thread Starter
Frenzied Member
Well I know that the order the code appears doesn't work, the name of the subroutine doesn't work, maybe the order it is added I'm not sure.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Sep 28th, 2004, 06:49 AM
#10
PowerPoster
Originally posted by Ideas Man
Well I know that the order the code appears doesn't work, the name of the subroutine doesn't work, maybe the order it is added I'm not sure.
Hi,
It appears to be something to do with the name chosen for the Event but it looks like a random choice based on the name. Try naming them X1_Click; X2_Click & X3_Click. For me the call order was X3; X2; X1.
I then added (typed not copied) X4 and the new call order was X1; X3; X2; X4.
I then changed X4 to X0 and the order was X1; X0; X3; X2
I then changed X2 to Button4 and the order was X1; Button4; X0; X3.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|