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 kinfxhk, 07-13-2026, 10:18 AM
      0 responses
      30 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 09:50 AM
      0 responses
      24 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 07:21 AM
      0 responses
      30 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-11-2026, 02:11 AM
      0 responses
      27 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by SalmaTrader, 07-07-2026, 10:26 PM
      0 responses
      141 views
      0 likes
      Last Post SalmaTrader  
      Working...
      X