Global Variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark A. Deal

    #1

    Global Variable

    If I store a value in the registry such as InDebugMode then I would like to
    be able to store whether we are in DebugMode across the application. In
    other words, I would like to use something like:

    IF DebugMode THEN
    LogFile.WriteEn try("We are in debug mode")
    END IF

    I would prefer to avoid hitting the registry every time.

    Can anybody offer any advise?

    Running Visual Studio .Net 2003.
    Delphi Convert---Kicking and Screaming :~)

    --
    Mark A. Deal
    Document & Data Solutions, LLC

    Time Matters AIC
    GhostFill Certified Consultant


  • Michael C#

    #2
    Re: Global Variable

    Create a module and declare the variable in there? Or create a class with a
    Shared DebugMode property?

    "Mark A. Deal" <nospam@idaknow .com> wrote in message
    news:%2354OnuMu FHA.1472@TK2MSF TNGP15.phx.gbl. ..[color=blue]
    > If I store a value in the registry such as InDebugMode then I would like
    > to
    > be able to store whether we are in DebugMode across the application. In
    > other words, I would like to use something like:
    >
    > IF DebugMode THEN
    > LogFile.WriteEn try("We are in debug mode")
    > END IF
    >
    > I would prefer to avoid hitting the registry every time.
    >
    > Can anybody offer any advise?
    >
    > Running Visual Studio .Net 2003.
    > Delphi Convert---Kicking and Screaming :~)
    >
    > --
    > Mark A. Deal
    > Document & Data Solutions, LLC
    > http://www.docsol.com
    > Time Matters AIC
    > GhostFill Certified Consultant
    >
    >[/color]


    Comment

    • Ken Tucker [MVP]

      #3
      Re: Global Variable

      Hi,

      You could make a shared variable in a class for that.

      The class

      Public Class Defaults
      Public Shared ReadOnly Property DebugMode() As Boolean
      Get
      Dim bDebug As Boolean = False
      #If debug Then
      bDebug=True
      #End If
      Return bDebug
      End Get
      End Property
      End Class


      To use

      Trace.WriteLine (Defaults.Debug Mode.ToString)



      Ken
      ----------------
      "Mark A. Deal" <nospam@idaknow .com> wrote in message
      news:%2354OnuMu FHA.1472@TK2MSF TNGP15.phx.gbl. ..[color=blue]
      > If I store a value in the registry such as InDebugMode then I would like
      > to
      > be able to store whether we are in DebugMode across the application. In
      > other words, I would like to use something like:
      >
      > IF DebugMode THEN
      > LogFile.WriteEn try("We are in debug mode")
      > END IF
      >
      > I would prefer to avoid hitting the registry every time.
      >
      > Can anybody offer any advise?
      >
      > Running Visual Studio .Net 2003.
      > Delphi Convert---Kicking and Screaming :~)
      >
      > --
      > Mark A. Deal
      > Document & Data Solutions, LLC
      > http://www.docsol.com
      > Time Matters AIC
      > GhostFill Certified Consultant
      >
      >[/color]


      Comment

      • Phill.  W

        #4
        Re: Global Variable

        "Mark A. Deal" <nospam@idaknow .com> wrote in message
        news:%2354OnuMu FHA.1472@TK2MSF TNGP15.phx.gbl. ..[color=blue]
        > I would like to be able to store whether we are in DebugMode
        > across the application.
        >
        > IF DebugMode THEN
        > LogFile.WriteEn try("We are in debug mode")
        > END IF[/color]

        If you want to know if you're currently debugging the code, use

        If System.Diagnost ics.Debugger.Is Attached Then
        End If

        If you want to know if you're running a Debug build of the program,
        you can use conditional compilation:

        #If DEBUG Then
        #End If

        Or, for a Boolean like this, you could just create a Global Boolean
        Variable in a Module.

        HTH,
        Phill W.


        Comment

        Working...