Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:39:31+00:00 2026-06-09T20:39:31+00:00

This is a small logic question. My datagrid has date time values in chronological

  • 0

This is a small logic question. My datagrid has date time values in chronological order.
If the user enters an out-of-order date time, the program should highlight the row which is out-of-order.
For eg: This is the initial order.

10/5/2010 11:59:59  
10/6/2010 00:00:00  
10/6/2010 11:59:59

Suppose the user enters

   10/5/2010 11:59:59   
    ***10/7/2010 00:00:00***    
    10/6/2010 11:59:59  
    10/7/2010 00:00:00 

here 10/7/2010 00:00:00 is the out of order and the program behaves correctly.

Suppose the user enters

10/5/2010 11:59:59
10/6/2010 00:00:00
***10/5/2010 11:59:59***
10/7/2010 00:00:00

Here 10/5/2010 11:59:59 is the out or order row. But the program highlights 10/6/2010 00:00:00.

Here’s my code to check the above:

for (int nRow = 1; nRow < pSeries.Count; ++nRow)
{
    // validation1
   if (!check_range(nRow, i, pSeries[nRow].tim))
   {
       row = nRow;
       err = (short)err_typ.e_out_range;
       goto err_exit;
   }
}

public bool check_range(int np, int nCol, DateTime dt)
{
    DataArray pdata = GetDataArray(nCol);

    bool valid = (np <= 0 || pdata[np - 1].Datetim <= dt) &&
         (np >= (pdata.Count - 1) || dt <= pdata[np + 1].Datetim );
    return valid;
}

DataArray is a user defined array of datetime values. pSeries,pData are of type DataArray.
So when I say pdata[np - 1].DateTime it refers to the datetime cell.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:39:32+00:00Added an answer on June 9, 2026 at 8:39 pm

    Your code says that for a sequence (A, C, B, D), C is considered out of order because C does not fall between A and B.

    In the case of the sequence (5.0, 6.0, 5.1, 7.0), your current code will find that 6.0 does not fit between 5.0 and 5.1, and therefore 6.0 is out of place. Your problem description, though, indicates that you have another criterion for deciding whether a row is out of place which is not represented in your code.

    I’m going to guess that the additional rule is something like this: if N+1 fits between N-1 and N, then N+1 is the row that is out of place, not row N.

    For the sequence (5.0, 6.0, 5.1, 7.0) if we first test this new rule, then it will flag 5.1 as the out of place row. If the new rule returns false, then we continue on with your existing code as a secondary test.

    Perhaps a simpler way to test this is to check that each row date is greater than or equal to the previous row date. Just one compare per row instead of two+. When you reach a row date that fails this test, you then need to “look around” to decide whether the “blame” is with the previous row or with the current row. It doesn’t matter how fast this “look around” code is because it will only be used in the error situation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is may be not program question, but i guess its program logic question.
Consider this small program: #include <stdio.h> #include <stdlib.h> // Change 60000 to 70000 and
I'm running this small C# test program launched from a pre-commit batch file private
I just did this question out of KN King's C Programming: A Modern Aprroach.
This is a design question. The design is pseudo-code and represents a small example
This more of an out of interest question than an urgently need an answer
I have this small class looking like this: private static int field1 = -
I have this small class called City that simply holds some information about a
We use this small utility method. But we don't like it. Since it's not
I'm building this small java applet in which I need a JPanel which will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.