Results 1 to 11 of 11

Thread: Break When a Variable Change

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Break When a Variable Change

    Say I have a variable. Say I want to know when does the function change.'

    On vs2008 I think on the watch I can edit watch and put something about it. What can I do about it now? There is no such option in the context menu if I click on a watch variable

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Break When a Variable Change

    There is no such feature in VS 2008. What you can do is set a breakpoint and then set a condition on that breakpoint, such that execution will break at that point if the value of some expression has changed since the last time execution passed that way.
    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
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: Break When a Variable Change

    I see but what about if I don't know where the value change? I am sure there is such feature in some old version of vb.net. I used it.

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

    Re: Break When a Variable Change

    It was a feature in VB6, I have never seen the feature in any version .NET, though I never used 2002.
    My usual boring signature: Nothing

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Break When a Variable Change

    VS has a feature to find all usages of a variable. You can use that and set breakpoints. Alternatively, you can use a property and set a breakpoint on the setter.
    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
    New Member
    Join Date
    Apr 2013
    Posts
    8

    Re: Break When a Variable Change

    This was a very useful feature in VB6. I am just now (finally) beginning to use VS .net and can't believe there is not a way to do this. Oh well!

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Break When a Variable Change

    Quote Originally Posted by jeffdb27 View Post
    This was a very useful feature in VB6. I am just now (finally) beginning to use VS .net and can't believe there is not a way to do this. Oh well!
    I've never once found a need for such a feature and I'm not sure that well-written VB.NET code would ever need it. Generally speaking, there shouldn't be all that many places that any variable's value changes. If the value is to be changed from an external source then it should be exposed via a property so there's really only one place the value should change.
    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

  8. #8
    New Member
    Join Date
    Apr 2013
    Posts
    8

    Re: Break When a Variable Change

    Quote Originally Posted by jmcilhinney View Post
    I've never once found a need for such a feature and I'm not sure that well-written VB.NET code would ever need it. Generally speaking, there shouldn't be all that many places that any variable's value changes. If the value is to be changed from an external source then it should be exposed via a property so there's really only one place the value should change.
    Well, in VB6 you had public (global) variables that could change all over the place. I am converting a rather large vb6 project and I'm not taking the time (at least at first) to put everything in classes. I am just trying to get it to work.

    But in this particular case, i wanted to watch a property of a control, specifcally the selectedtext property of a MaskedTextBox. I cannot get the selection to show (be highlighted) when i set the selection programatically. It shows if selected with the mouse but not in code. This works fine for regular text boxes. I don't think the watch would have helped in this case, but that's why I was looking for it.

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

    Re: Break When a Variable Change

    You actually ARE putting everything in classes, though you may not realize you are. EVERYTHING in .NET is in a class. If you put it in a module, the module is quietly turned into a class with all Shared members.

    Personally, I did find that feature in VB6 to be quite useful, and have missed it at times over the years. I can only assume that the reason it was removed was that it was accomplished using somekind of ugly hack that MS didn't want to have violating the purity of the current model. That may sound like a rather overwrought reason, but there is at least one other fine example of this: The odd behavior of the Load event on Win64 systems.

    Frankly, I made a small amount of use of the MaskedTextBox, but only enough to decide that, as a user, I find it unpleasant. I don't know of a great, and general, replacement for it, but that control is one that I avoid as much as possible.
    My usual boring signature: Nothing

  10. #10
    New Member
    Join Date
    Apr 2013
    Posts
    8

    Re: Break When a Variable Change

    Yes, I know everything is in a class in .net, but you get my point!

    I have read other threads where people don't like the MaskedTextBox and say it is something to be avoided. I just dont know why, since all the properties are there (.selectionstart, .selectionlength), that this rather simple code isn't working. The mask part is working fine.

    I'll probably abandon it as well. And just use the validate (now validating, I think) function to force proper input.

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

    Re: Break When a Variable Change

    I personally feel that the MaskedTextBox is painful to use. This isn't some comment on the quality of the control from a programming perspective, or the properties exposed, I just don't think that it works the way I expect it to work. On the other hand, I can't be more specific than that because it just feels wrong without me being able to say what would feel right. If I could decide what I would prefer it to do, I'd write my own (maybe, I haven't really found all that much use for it, so perhaps I'd do something else), but I can't decide what I don't like about it.
    My usual boring signature: Nothing

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