Results 1 to 9 of 9

Thread: Renaming variables

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2012
    Posts
    129

    Renaming variables

    Hi folks.

    In previous VB versions renaming a variable within it's declaration caused every use of that variable to be updated. This doesn't seem to be happening with VB2015.

    Is this a due to me missing a setting somewhere? Or has this functionality been taken out in this version?

    Thanks.

  2. #2
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: Renaming variables

    Depending on which version you're using, you may have access to the Rename Variable command in the Refactor menu. I don't quite know where you'd look for it, as I use R# in place of the VS supplied refactoring tools, but you can use that on the declaration or any usage of the variable. I suspect it probably isn't in the free editions of VS though.

  3. #3
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Renaming variables

    You'll have to be a little more detailed, as far as I know this has been available in every version of VB since around 2008. If you mean "It missed one of my variables", sometimes it gets confused, particularly if you do the rename when there are errors in your code.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2012
    Posts
    129

    Re: Renaming variables

    Dim X as integer=nothing
    X=5

    Now if I go back to the declaration line and rename X to Y, the line X=5 doesn't get updated. It's not missing a variable here and there, it's not updating any. The same for procedures, forms, classes, basically anything that is declared or created. I've just moved up from 2012 where this is completely automatic.

  5. #5
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Renaming variables

    Wait.

    Are you right-clicking and choosing "Rename" in some menu, or using F2, or are you just highlighting it and typing a new name and expecting it to update?

    It's never really worked automatically. I've been using VB since 2003 and I've always had to tell the IDE if I wanted a rename like this. If you had it automatically updating in VS 2012, you had something installed that was doing it for you.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2012
    Posts
    129

    Re: Renaming variables

    Hmm. Well, that's confusing. I've just gone back to 2012 to test this and it works absolutely fine just over typing, all the updates happen automatically as soon as the cursor leaves the line. I don't have any additional software installed, it's a standard pro installation. (I'm pretty sure!)

    However, the Rename menu option does work, In a rather strange way!

  7. #7
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Renaming variables

    I've only ever seen it for capitalization changes, like if I change "x" to "X" it adjusts it (in VB only). I don't have a version of 2012 installed, only 2013. Maybe it was a weird one-time thing? We'll have to wait for someone else to confirm.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  8. #8
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Renaming variables

    I have to say I have never had to use the rename commad. Never even knew it was present. I have always simply edited the variable declaration. The only time it ever fails is if as Sitten Spynne says ... there is an error somewhere. Typically the blue wiggly lines are present. Fix the error and everything refactors.

    This has been true in 2005, 2008, 2010, 2012, and 2013. I haven't bothered with 2015 yet as I do not see any huge advantage to it.

    BTW in your example I see you setting an integer to nothing.
    Not sure if that constitutes an error.
    I don't ever do that. I always set it to a value or I do not set it.

    Another common error that throws a monkey wrench into refactoring is accidentally writing code outside a procedure.
    ---

    History tidbit
    VB6 had / has a refactoring issue that threw no errors whatsoever.

    If you created a variable with the same name, but different case as a goto label the variable name would refactor to the same case as the goto label.

    It was crazy frustrating until I figured it out.
    (Also one of the many reasons I stopped using goto statements.)
    Last edited by Gruff; Nov 28th, 2015 at 12:09 PM.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,041

    Re: Renaming variables

    I have never seen it happen automatically. If I change the name of something I get a small menu that allows me to rename if I choose to, but I have to take real action for the change to happen, it isn't automatic...in most cases. I think that the change is more automatic if I change a form name, but even then I am asked and have to confirm the change.

    I'm not sure that I'd want it to change automatically. Usually I DO want that change, but not always. With an automatic change you'd have to manually find them and change them back when it got the wrong ones.
    My usual boring signature: Nothing

Tags for this Thread

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