PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Change Signature question-VBForums
Results 1 to 11 of 11

Thread: Change Signature question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    416

    Change Signature question

    Hello

    I have the following line of code in my VS 2017 Web page project:

    Code:
    Protected Sub btnReg_Click(ByVal e As System.EventArgs, ByVal sender As Object) Handles btnReg.Click
    However, a get a yellow light bulb that appears and suggests I change the above code to:

    Code:
    Protected btnReg_Click(sender As Object, e As EventArgs)
    or

    Code:
    Protected btnReg_Click(e As EventArgs, sender As Object)
    These two suggestions appear in a 'Change Signature' dialogue box.

    Which would be the best option, please?

    Thanks!

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,788

    Re: Change Signature question

    If that is supposed to be a Click event handler for a Button then you need to swap the parameters around. The 'sender' is ALWAYS first and 'e' is ALWAYS second in event handlers.

    Also, why is it declared Protected instead of Private? You shouldn't be calling event handlers directly so there's no good reason for that, as far as I can tell.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    416

    Re: Change Signature question

    Thanks jmcilhinney for your explanation.

    When I replace

    Code:
    Protected Sub btnReg_Click(ByVal e As System.EventArgs, ByVal sender As Object) Handles btnReg.Click
    with either

    Code:
    Private btnReg_Click(sender As Object, e As EventArgs)
    or

    Code:
    Protected btnReg_Click(sender As Object, e As EventArgs)
    I get various errors

    Attachment 161085

    so I thought I had better ignore the light bulb and retain the code that I originally had.

    When you write

    you need to swap the parameters around
    do you mean the order of the parameters here:

    Code:
    cmd.Parameters.AddWithValue("@username", username.Text)
                    cmd.Parameters.AddWithValue("@strEmail", strEmail.Text)
                    cmd.Parameters.AddWithValue("@Hash", "Production based on simple ciphers and fixed encryption keys")
    In my MS Access db, the three columns are in the order (from left to right): username, strEmail, Hash.

    Thanks again for your help.

    Regards

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,118

    Re: Change Signature question

    Quote Originally Posted by SteveHi View Post
    I get various errors

    Attachment 161085

    so I thought I had better ignore the light bulb and retain the code that I originally had.
    No, you should fix the errors... because your existing code is wrong.

    Unfortunately you decided to not give any indication of what the errors are, so we can't help you fix them. I assume at least one is caused by the fact you missed out the very important word Sub (and it is probably causing all the other errors).

    However, based on the samples of code in your post, what you should probably have for that line is this:
    Code:
    Private Sub btnReg_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReg.Click

    When you write
    you need to swap the parameters around
    do you mean the order of the parameters here:

    Code:
    cmd.Parameters.AddWithValue("@username", username.Text)
                    cmd.Parameters.AddWithValue("@strEmail", strEmail.Text)
                    cmd.Parameters.AddWithValue("@Hash", "Production based on simple ciphers and fixed encryption keys")
    In my MS Access db, the three columns are in the order (from left to right): username, strEmail, Hash.
    No, he was referring to the parameters to the Sub, which is the part inside the brackets.

    In terms of cmd.parameters, the order you have them is not related to the order of items in the database, but the order of the items in your SQL statement. Based on the little I can see in the screenshot, they seem to be correct.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,788

    Re: Change Signature question

    Given that I referred explicitly to 'sender' and 'e', it should have been obvious that those were the parameters I was referring to; the method parameters. All you need to do was what I said, i.e. change this:
    vb.net Code:
    1. Protected Sub btnReg_Click(ByVal e As System.EventArgs, ByVal sender As Object) Handles btnReg.Click
    to this:
    vb.net Code:
    1. Protected Sub btnReg_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReg.Click
    That said, I'd have it like this:
    vb.net Code:
    1. Private Sub btnReg_Click(sender As Object, e As EventArgs) Handles btnReg.Click
    There's generally no good reason for an event handler to not be Private, the ByVal keywords are superfluous and the qualifying namespace on EventArgs is also superfluous.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    416

    Re: Change Signature question

    Thank you Si the Geek

    I have replaced what I had just before I read your reply, which was:

    Code:
    Private Sub btnReg_Click(sender As System.Object, e As System.EventArgs) Handles btnReg.Click
    with your:

    Code:
    Private Sub btnReg_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReg.Click
    Again that yellow light bulb pops up with the 'Change Signature' dialogue box:

    Name:  SiTheGeek.jpg
Views: 32
Size:  26.1 KB

    Thanks again

    Steve

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    416

    Re: Change Signature question

    Thank you Si the Geek

    I have replaced what I had just before I read your reply, which was:

    Code:
    Private Sub btnReg_Click(sender As System.Object, e As System.EventArgs) Handles btnReg.Click
    with your:

    Code:
    Private Sub btnReg_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReg.Click
    Again that yellow light bulb pops up with the 'Change Signature' dialogue box:

    Name:  SiTheGeek.jpg
Views: 32
Size:  26.1 KB

    Thanks again

    Steve

  8. #8
    Fanatic Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    848

    Re: Change Signature question

    IT looks as though the suggestion is just to remove the System prefix from the two data types, if you have imported the System namespace (either at the top of the file or in the project settings) you don't need to qualify the types declared in that namespace.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    416

    Re: Change Signature question

    Thanks PlausiblyDamp

    Yes, I have the System namespace and used jmcilhenny's suggestion of

    Code:
    Private Sub btnReg_Click(sender As Object, e As EventArgs) Handles btnReg.Click
    Cheers to you all!

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    416

    Re: Change Signature question

    Thanks PlausiblyDamp

    Yes, I have the System namespace and used jmcilhenny's suggestion of

    Code:
    Private Sub btnReg_Click(sender As Object, e As EventArgs) Handles btnReg.Click
    Cheers to you all!

  11. #11
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,788

    Re: Change Signature question

    Note that, when the forum tells you that you need to wait 29 seconds (or thereabouts) to post again, it actually has submitted your post. If you scroll down the page a little you can see that. You don't actually need to try to post a second time or you'll end up double-posting, as you've done here a couple of times. It seems to happen when including CODE or HIGHLIGHT tags and maybe QUOTE tags too. Maybe any tags, although I haven't tested that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width