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 argusthome, Yesterday, 10:06 AM
      0 responses
      17 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      16 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      14 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      9 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      36 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X