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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      669 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      378 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      111 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      575 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      580 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X