vb.net - Global Variable change tracking - Stack Overflow

Long time ago on VB6 it was possible to stop the code when a global variable was changing from 0 to 1.

Long time ago on VB6 it was possible to stop the code when a global variable was changing from 0 to 1. With VB 2022 there is no way I can do that. I look at all the documentation on Conditional breakpoint but it never stop on a global variable. It stop at designated place in the code but it cannot be based on the variable itself. It's worse if I am trying to stop on a double array like a(b,c). My code is 40 years old. I will not change 200 MB of code to be more adapted to the new way of programming. Then if somebody can tell how to stop code when the global integer array "a(1,1)" used 200 times in the code changes from 0 to 1, that will be nice.

Try many different way with Conditional Breakpoint

Long time ago on VB6 it was possible to stop the code when a global variable was changing from 0 to 1. With VB 2022 there is no way I can do that. I look at all the documentation on Conditional breakpoint but it never stop on a global variable. It stop at designated place in the code but it cannot be based on the variable itself. It's worse if I am trying to stop on a double array like a(b,c). My code is 40 years old. I will not change 200 MB of code to be more adapted to the new way of programming. Then if somebody can tell how to stop code when the global integer array "a(1,1)" used 200 times in the code changes from 0 to 1, that will be nice.

Try many different way with Conditional Breakpoint

Share Improve this question edited Nov 20, 2024 at 21:44 StayOnTarget 13.1k11 gold badges64 silver badges107 bronze badges asked Nov 20, 2024 at 21:42 Jean-JeJean-Je 11 silver badge1 bronze badge 2
  • As far as I know, data breakpoints in current Visual Studio versions are native code only, so any workaround will involve modifying the code so that things that are currently array assignments get turned into Property Set calls instead (as with the answer currently posted). – Craig Commented Nov 21, 2024 at 20:46
  • This is the answer I didn't want to see. Now I understand why the VB6 method doesn't exist anymore. Old programmers who still maintain their old code understand that the proposed solution is much harder to implement than the simple check in VB6. I have changed my programming methods a lot and VB has a lot of tools that allow you to find the problem and modify the code for a simpler search next time. But when in a critical period the program stops working because of a value that changes somewhere in the program, stopping on a value that has changed was very useful. Thanks. – Jean-Je Commented Nov 21, 2024 at 21:52
Add a comment  | 

1 Answer 1

Reset to default 1

You can use a Class with a Default property:

Public Class ArrayClass

    Dim internalArray(50, 50) As Integer

    Default Public Property Accessor(x As Integer, y As Integer) As Integer
        Get
            Return internalArray(x, y)
        End Get
        Set(value As Integer)
            If x = 1 And y = 1 Then
                Debug.WriteLine("Eureka")
                internalArray(x, y) = value
            End If
        End Set
    End Property

End Class

This should give you the ability to add a breakpoint in the class setter for the Accessor property.

You can then create a Shared instance of that class and name it a:

Public Shared a As New ArrayClass

Making a Shared will make it act like a global variable. It might need to be prefixed by the class you create it in. For example, if you declare a in your Application class, you will have to refer to it as Application.a in other classes.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742326534a4422864.html

相关推荐

  • vb.net - Global Variable change tracking - Stack Overflow

    Long time ago on VB6 it was possible to stop the code when a global variable was changing from 0 to 1.

    9小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信