Forum Discussion

ferranferri's avatar
ferranferri
Occasional Contributor
13 years ago

DDT driver have a very strange behaviour

Hello all,



I'm havin problems using DDT drivers to read  an excel row. The program is like this



var Driver = DDT.ExcelDriver("..\\files\\test4Dxx.xls", sheet_Name);        


DDT.CurrentDriver.Next();

  var activate_id = new Array();

  for (var k = 0; k < dict_count; k++)

  {

    Log.Message("activation dict " + DDT.CurrentDriver.Value(k + 1));

    var kk = DDT.CurrentDriver.Value(k + 1);

    if(kk == "TRUE"){

      activate_id = true;

    }else{

      activate_id = false;      

    }              

  }


The code is quite straightforward. The row is composed by a name in the first colunm and then about 80 values TRUE or FALSE. The format of all cells is TEXT. The result of the log is TRUE, TRUE,TRUE, and then about 70 nulls and then the last 2 cells are FALSE. So, some cells are correctly readed and the other are null. Office version is 2003. If none of this values was readed, I could think that my code is wrong but the fact that some values are correctly readed and the others aren't... is very strange.





Any help will be welcome.

Thanks

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Is it possible to post the Excel file?  It sounds like it's not a problem with the TestComplete code and objects but something unique about what's going on in your Excel file.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The way I'm seeing it, you're not even reading the correct row.  Your DDT.CurrentDriver.Next is taking you to the row labeled "dict_id", not the row labeled "activation dict".



    So, first of all, I'd alter you code like so:



    var Driver = DDT.ExcelDriver(Project.Path + "test4Dss.xls", "test_suite_001");        






    while (DDT.CurrentDriver.Value(0) != "ACTIVE_DICT")


    {


    DDT.CurrentDriver.Next()


    }






      var activate_id = new Array(); 


      for (var k = 0; k < 78; k++) 


      { 


        Log.Message("activation dict " + DDT.CurrentDriver.Value(k + 1)); 


        var kk = DDT.CurrentDriver.Value(k + 1); 


        if(kk == "TRUE"){ 


          activate_id = true; 


        }else{ 


          activate_id = false;       


        }               


      } 


    }




    Note the section in bold.  That will make sure you're on the correct row.



    The next thing is that the values in your "ACTIVE_DICT" row, within the Excel sheet, are entered as booleans and not strings.  So, when it tries to do a string comparison, it's not matching.  The reason why some work and some don't has to do with the values in the rows above it.  The way the Jet engine works is that, unless otherwise specified, the value in the first row for any given column, the data type of that value determines the data type of ALL values in that column.  So, for the first few columns, all values in that column are treated as strings because the first value is a string.  But after you get out a few columns, the first value is actually numeric so it tries to read the TRUE or FALSE, not as strings, but as numbers and it can't convert.



    As a general rule, you need to make sure, when using DDT drivers, to make all values in the same column have the same data type.  Try converting your date in the DICT_ID row to be forced to be strings.




    FYI, standard usage of the DDT drivers is to read data out row by row and not column by column.  That's why the behavior is dependent upon formatting of values based upon row.