Results 1 to 5 of 5

Thread: [RESOLVED] button click

  1. #1

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Resolved [RESOLVED] button click

    It was pretty simple in VB6 to invoke the 'click' event of a command button (i.e.; btnNext_Click).

    I am having difficulty trying to do the same think in VS2008.

    I am getting errors at line btnNext_Click():

    Error 1 Argument not specified for parameter 'e' of 'Private Sub btnNext_Click(sender As Object, e As System.EventArgs)'.


    Error 2 Argument not specified for parameter 'sender' of 'Private Sub btnNext_Click(sender As Object, e As System.EventArgs)'.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: button click

    in vb.net the signature of your event procedure should match.
    The easiest way is to let visual studio generate the procedure. For that you do it just as you do in VB6. Either double-click the button in designer, which will generate the default method (click) signature, or select your button name from left dropdown in code window and "Click" from the right dropdown.
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
    End Sub
    Alternatively, you can type this yourself, but then be careful about it; you may do it wrong.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: button click

    If you are calling the button click handler directly, it requires those two arguments. The sender argument holds the button that raised the event, and the e argument, in the case of a button click, holds nothing useful at all. Therefore, you could call it with:

    btnNext_Click(Nothing,Nothing)

    but that's not necessarily a good idea. If the sub is using either of those arguments (it is unlikely to be using e in the button click, but sender is possible), then this will most likely cause a crash.

    The more typical solution to this would be to make a new sub that has all the code from the click event handler, and have the click event handler call this sub, as well as anything else that needs to call it. That way you are getting just the arguments you need, rather than those mandated by the event. You could also look into PerformClick.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: button click

    The performClick seems to be acceptable to it. Thanks a bunch!
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: button click

    Quote Originally Posted by Pasvorto View Post
    The performClick seems to be acceptable to it. Thanks a bunch!
    Don't use PerformClick if you want to be happy unless you know fully about it.
    It doesn't fire in all cases.

    The better surer way is to either move your code into a different procedure and call it from both locations or use Button1_Click(Nothing,Nothing). The former way being the better of the two.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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