scope and access

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    scope and access

    I have a class trying to access some public static variables in another
    class and one I can't seem to see.

    In the class where they are defined, the look like:

    public static object statusOutput = null;
    public static string fileInProcess = null;
    public static bool serviceRunning = false;

    The only difference between them is the type.

    temp = FieldNameMapSet up.FieldNameMap Setup.serviceRu nning;
    stemp = FieldNameMapSet up.FieldNameMap Setup.fileInPro cess;
    Log.Write(Field NameMapSetup.Fi eldNameMapSetup .statusOutput);


    But for some reason I can't seem to see the statusOutput variable from the
    other class. I can see fileInProcess and serviceRunning.

    But statusOutput gives me the error:

    'FieldNameMapSe tup.FieldNameMa pSetup' does not contain a definition for
    'statusOutput'

    But as you can see from above, it does???? It doesn't show in the
    intellisense either.

    Also, I have a Textbox in that same class that gives me the same error:

    FieldNameMapSet up.FieldNameMap Setup.Status.Te xt

    It says that Status does not exists, but it does as a TextBox.

    What do I have to do to access this Textbox and statusOutput?

    Thanks,

    Tom


  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

    #2
    Re: scope and access

    tshad wrote:
    I have a class trying to access some public static variables in another
    class and one I can't seem to see.
    >
    In the class where they are defined, the look like:
    >
    public static object statusOutput = null;
    public static string fileInProcess = null;
    public static bool serviceRunning = false;
    >
    The only difference between them is the type.
    >
    temp = FieldNameMapSet up.FieldNameMap Setup.serviceRu nning;
    stemp = FieldNameMapSet up.FieldNameMap Setup.fileInPro cess;
    Log.Write(Field NameMapSetup.Fi eldNameMapSetup .statusOutput);
    >
    >
    But for some reason I can't seem to see the statusOutput variable from the
    other class. I can see fileInProcess and serviceRunning.
    >
    But statusOutput gives me the error:
    >
    'FieldNameMapSe tup.FieldNameMa pSetup' does not contain a definition for
    'statusOutput'
    >
    But as you can see from above, it does???? It doesn't show in the
    intellisense either.
    >
    Also, I have a Textbox in that same class that gives me the same error:
    >
    FieldNameMapSet up.FieldNameMap Setup.Status.Te xt
    >
    It says that Status does not exists, but it does as a TextBox.
    >
    What do I have to do to access this Textbox and statusOutput?
    Can you post a complete code sample that shows the problem ?

    It would make troubleshooting a lot easier !

    Arne

    Comment

    • Jeff Winn

      #3
      Re: scope and access

      Try cleaning the solution and rebuilding, sounds like a problem with the
      vshost process screwing things up again.

      "tshad" <tshad@dslextre me.comwrote in message
      news:OefFKxZ1IH A.6096@TK2MSFTN GP06.phx.gbl...
      >I have a class trying to access some public static variables in another
      >class and one I can't seem to see.
      >
      In the class where they are defined, the look like:
      >
      public static object statusOutput = null;
      public static string fileInProcess = null;
      public static bool serviceRunning = false;
      >
      The only difference between them is the type.
      >
      temp = FieldNameMapSet up.FieldNameMap Setup.serviceRu nning;
      stemp = FieldNameMapSet up.FieldNameMap Setup.fileInPro cess;
      Log.Write(Field NameMapSetup.Fi eldNameMapSetup .statusOutput);
      >
      >
      But for some reason I can't seem to see the statusOutput variable from the
      other class. I can see fileInProcess and serviceRunning.
      >
      But statusOutput gives me the error:
      >
      'FieldNameMapSe tup.FieldNameMa pSetup' does not contain a definition for
      'statusOutput'
      >
      But as you can see from above, it does???? It doesn't show in the
      intellisense either.
      >
      Also, I have a Textbox in that same class that gives me the same error:
      >
      FieldNameMapSet up.FieldNameMap Setup.Status.Te xt
      >
      It says that Status does not exists, but it does as a TextBox.
      >
      What do I have to do to access this Textbox and statusOutput?
      >
      Thanks,
      >
      Tom
      >

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: scope and access

        On Jun 24, 2:47 am, "tshad" <ts...@dslextre me.comwrote:

        <snip>
        What do I have to do to access this Textbox and statusOutput?
        As Arne says, a short but complete program would make life a lot
        easier. However, a few things:

        1) Having a namespace and a class of the same name can be problematic.
        Avoid it where possible.

        2) Public variables (other than readonly immutable ones) are generally
        a very bad idea.

        3) Static variables are often a bad idea. Dependency injection is one
        technique which avoids it in many situations. Statics may be the right
        solution in this particular case, but it's worth thinking about
        whether there's a useful encapsulation you could introduce, along the
        lines of a StatusMonitor or something similar.

        Jon

        Comment

        • tshad

          #5
          Re: scope and access


          "Arne Vajhøj" <arne@vajhoej.d kwrote in message
          news:48605501$0 $90265$14726298 @news.sunsite.d k...
          tshad wrote:
          >I have a class trying to access some public static variables in another
          >class and one I can't seem to see.
          >>
          >In the class where they are defined, the look like:
          >>
          > public static object statusOutput = null;
          > public static string fileInProcess = null;
          > public static bool serviceRunning = false;
          >>
          >The only difference between them is the type.
          >>
          > temp = FieldNameMapSet up.FieldNameMap Setup.serviceRu nning;
          > stemp = FieldNameMapSet up.FieldNameMap Setup.fileInPro cess;
          > Log.Write(Field NameMapSetup.Fi eldNameMapSetup .statusOutput);
          >>
          >>
          >But for some reason I can't seem to see the statusOutput variable from
          >the other class. I can see fileInProcess and serviceRunning.
          >>
          >But statusOutput gives me the error:
          >>
          >'FieldNameMapS etup.FieldNameM apSetup' does not contain a definition for
          >'statusOutpu t'
          >>
          >But as you can see from above, it does???? It doesn't show in the
          >intellisense either.
          >>
          >Also, I have a Textbox in that same class that gives me the same error:
          >>
          >FieldNameMapSe tup.FieldNameMa pSetup.Status.T ext
          >>
          >It says that Status does not exists, but it does as a TextBox.
          >>
          >What do I have to do to access this Textbox and statusOutput?
          >
          Can you post a complete code sample that shows the problem ?
          >
          It would make troubleshooting a lot easier !
          I agree, but the 2 files are both really large. I have them together
          exactly like the I have shown, however. The question would be why would 2
          of them work fine and the 3rd one not work. The only difference appears to
          be the fact that one of them is an object - also the TextBox doesn't work,
          as I mentioned. The only thing there is that VS sets it up as private and
          I changed it to public - so I would have thought I would be able to access
          it from my other file.

          Thanks,

          Tom
          >
          Arne

          Comment

          • Jon Skeet [C# MVP]

            #6
            Re: scope and access

            On Jun 24, 3:32 pm, "tshad" <t...@dslextrem e.comwrote:
            Can you post a complete code sample that shows the problem ?
            >
            It would make troubleshooting a lot easier !
            >
            I agree, but the 2 files are both really large.
            Arne didn't ask you to post your original code. He asked you to post
            complete code which shows the problem. The best way to proceed is to
            take a copy of the original code, and start pruning it. Get rid of
            everything which isn't strictly necessary just to show the problem. If
            possible, get rid of all GUI stuff as that isn't usually necessary but
            *is* usually bulky.

            In the course of pruning, you may well find the problem. If so, great.
            If not, you've then got a situation which we can all reproduce so
            we'll be able to help you *much* more easily.

            Jon

            Comment

            • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

              #7
              Re: scope and access

              tshad wrote:
              "Arne Vajhøj" <arne@vajhoej.d kwrote in message
              news:48605501$0 $90265$14726298 @news.sunsite.d k...
              >tshad wrote:
              >>But for some reason I can't seem to see the statusOutput variable from
              >>the other class. I can see fileInProcess and serviceRunning.
              >>>
              >>But statusOutput gives me the error:
              >>>
              >>'FieldNameMap Setup.FieldName MapSetup' does not contain a definition for
              >>'statusOutput '
              >>>
              >>But as you can see from above, it does???? It doesn't show in the
              >>intellisens e either.
              >Can you post a complete code sample that shows the problem ?
              >>
              >It would make troubleshooting a lot easier !
              >
              I agree, but the 2 files are both really large. I have them together
              exactly like the I have shown, however. The question would be why would 2
              of them work fine and the 3rd one not work. The only difference appears to
              be the fact that one of them is an object - also the TextBox doesn't work,
              as I mentioned. The only thing there is that VS sets it up as private and
              I changed it to public - so I would have thought I would be able to access
              it from my other file.
              Make a copy of the files and cut them down to the minimum needed to
              illustrate the problem.

              It will make it possible for us to help.

              And BTW the process of cutting down the code may very well enable
              you to find the problem yourself before even posting the code.

              Arne

              Comment

              Working...