Forum Discussion

Dewayne_Pinion's avatar
Dewayne_Pinion
Contributor
11 years ago

Issue trying to compare date value in a while loop

Hello all,

This is making me pull my hair out, and I am sure it is something simple I am just missing. I have a datepicker control on a form that I am trying to evaluate with a while loop and have the loop stop when the datepicker equals a certain value:

 

while (RollDate.Text != "12/1/2014") 
    {
    
      mModDRI();
      
      fEdit();
      
      RollDate = GetDatePicker("NativeClrObject.Name",dtpCurrentDate);
   
      EnterDRIValues();
  
      Rollover();
    }

This code fails to exit and the loop keeps continuing even after 12/1/2014 has been reached. If I try the same comparison in an if statement:

 

 RollDate = GetDatePicker("NativeClrObject.Name",dtpCurrentDate);
  
  if(RollDate["Text"] != "12/1/2014")
    Log["Error"]("Date is incorrect","Date displayed is" + RollDate["Text"]);

On 12/1/2014 the script execution passes and no error is posted to the log, as expected.

 

So what am I missing? :)

3 Replies

  • chrisb's avatar
    chrisb
    Regular Contributor

    I think you may have cut and paste the variable name dtpCurrentDate. So you are not actually getting the date value back from the date picker function because you are passing 'dtpCurren?Date' instead of 'dtpCurrentDate'.

     

     

    Delete this variable in the Test Complete IDE, re-type it and try again.

     

    Also you may want to consider putting a counter in your loop so that after n number of times it returns rather than getting stuck in the loop if your value is not found. You test will run forever if the value isn't found which I assume is a possibility if you are testing it.

    • Dewayne_Pinion's avatar
      Dewayne_Pinion
      Contributor

      Weird. I will try that thanks. The reason I cannot use a counter is that it is date based. We are rolling over accounting information and at the end of the month/first of next month, it creates an entry into a General Ledger, so I always need it to stop on the 1st day of the month. However, based off of the company chosen to perform the rollover, it may start at any date within the month, for any month. So I thought this might be the best way to handle it, although there may be a better way. 

      • mtsmith's avatar
        mtsmith
        Contributor

        Also try checking the date format and verify that RollDate.Text is formatted without leading zeros:  is  RollDate.Text "12/1/2014" or "12/01/2014".