Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Testing for null Time object

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Testing for null Time object

    Not sure this is really an NT8 issue but I'm posting it here as I'm refactoring some older code in NT8. Basically I wrote myself a Print method with PrintLevels - similar to LogLevels. I'm plotting a lot of context for every print call I'm making, part of it is the Time[0].

    Only problem I'm running into is that sometimes Print(value, PrintLevel) is being called during the initialization process. And Time[0] throws one of these:

    Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    Not good. I'm trying to test for it like this:

    String time = (Time == null || Time.Count == 0) ? "" : Time[0].ToString();

    Not helping though - still getting that exception. Anyone know how to properly test for this? Obviously this doesn't come up often as usually nobody calls Time[0] before the bars are flowing.

    Thanks in advance.

    #2
    Never mind - I figured it out. This is my solution:

    Code:
    String time = "";
    
    if (State != State.SetDefaults && State != State.Configure && State != State.DataLoaded 
    && Time != null  && Time.Count > 0) {
    	time = Time[0].ToString();
    }
    Last edited by molecool; 06-02-2015, 05:21 AM.

    Comment


      #3
      Hello molecool,

      Thank you for your post.

      Glad you were able to resolve this matter.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by kujista, Today, 05:44 AM
      0 responses
      5 views
      0 likes
      Last Post kujista
      by kujista
       
      Started by ZenCortexCLICK, Today, 04:58 AM
      0 responses
      5 views
      0 likes
      Last Post ZenCortexCLICK  
      Started by sidlercom80, 10-28-2023, 08:49 AM
      172 responses
      2,281 views
      0 likes
      Last Post sidlercom80  
      Started by Irukandji, Yesterday, 02:53 AM
      2 responses
      18 views
      0 likes
      Last Post Irukandji  
      Started by adeelshahzad, Today, 03:54 AM
      0 responses
      8 views
      0 likes
      Last Post adeelshahzad  
      Working...
      X