Results 1 to 3 of 3

Thread: Sub being called twice [Resolved]

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Red face Sub being called twice [Resolved]

    I was creating a very simple db application, and noticed that when I was clicking the navigation buttons (Next, Previous, First, Last), the sub being used to handle it is being called twice.

    I commented out all the code in the sub, and stepped through the code, and it was still being called twice.

    Here's what I have:

    VB Code:
    1. 'First, add the handlers
    2. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.         AddHandler cmdPrevious.Click, AddressOf Navigation
    4.         AddHandler cmdFirst.Click, AddressOf Navigation
    5.         AddHandler cmdLast.Click, AddressOf Navigation
    6.         AddHandler cmdNext.Click, AddressOf Navigation
    7.  
    8.        
    9.     End Sub
    10.  
    11. 'Then:
    12.  
    13.     Private Sub Navigation(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFirst.Click, cmdLast.Click, cmdNext.Click, cmdPrevious.Click
    14.  
    15. MessageBox.Show "Bing"
    16.  
    17.     End Sub

    Why is it being called twice?
    Last edited by mendhak; May 26th, 2004 at 03:35 AM.

  2. #2
    Hyperactive Member vbud's Avatar
    Join Date
    Jan 2002
    Location
    Mru 20 17S, 57 33E Goal: Get out of the BOX Status: In The Shadows!!! Target Posts: 3,000,000,000
    Posts
    378
    I think that since you already have a sub to handle the Click event of the buttons, namely "Private Sub Navigation" then you need not have AddHandler in your form load, its either one or the other.
    >!v!<
    Free your mind, stop thinking
    http://inspirone.blogspot.com

    Please rate this post if it helped you

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    D'oh!!

    You're right. I don't need to include that "handles whatever.click" part.

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