Results 1 to 10 of 10

Thread: Order of Sequence for Multiple Subroutines Handling the Same Event

  1. #1

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    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:
    1. Private Sub Sub1(...) Handles Button1.Click
    2. ...
    3.  
    4. Private Sub Sub2(...) Handles Button1.Click
    5. ...
    6.  
    7. Private Sub Sub3(...) Handles Button1.Click
    8. ...
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  2. #2
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    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

  3. #3

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718
    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)

  4. #4
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    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.

  5. #5

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718
    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)

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  7. #7
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    code
    VB Code:
    1. Dim b As New Button()
    2.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.         b.Text = "Button1"
    4.         AddHandler b.Click, AddressOf b_click1  ' first
    5.         AddHandler b.Click, AddressOf b_click2  ' second    
    6.         AddHandler b.Click, AddressOf b_click3  ' third
    7.         Me.Controls.Add(b)
    8.     End Sub
    9.  
    10.     Sub b_click1(ByVal sender As Object, ByVal e As EventArgs)
    11.         MessageBox.Show("fist")
    12.     End Sub
    13.     Sub b_click2(ByVal sender As Object, ByVal e As EventArgs)
    14.         MessageBox.Show("second")
    15.     End Sub
    16.     Sub b_click3(ByVal sender As Object, ByVal e As EventArgs)
    17.         MessageBox.Show("third")
    18.     End Sub

  8. #8
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  9. #9

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718
    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)

  10. #10
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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
  •  



Click Here to Expand Forum to Full Width