Forum Discussion

ZooZoo's avatar
ZooZoo
Occasional Contributor
14 years ago

How to handle Excel or CSV Drivers

Am using the below code to read the data form .txt file:-


 


function dbtest(fname)

{

var f1name = "C:\\TestData\\" + fname + ".txt";



 



// Creates the driver

var Driver2 = DDT["CSVDriver"](f1name);

// Iterates through records

while (! Driver2["EOF"]() )

{

AppScriptDriver();

Driver2["Next"]();

}

// Closing the driver

DDT["CloseDriver"](Driver2["Name"]);

}



function DbMasterBatchController()

{

var Driver1;

// Creates the driver

Driver1 = DDT["CSVDriver"]("C:\\TestData\\MBA.txt");

// Iterates through records

while (! Driver1["EOF"]() )

{

fname =
DDT["CurrentDriver"]["Value"](1);

dbtest(fname);

Driver1["Next"]();

}

// Closing the driver

DDT["CloseDriver"](Driver1["Name"]);

Log["Warning"]("Driver closed");

}



while reading the second line in the .txt file (main function) it is giving the error "DDT.CurrentDriver is null or not an object"



If i have only one driver it is working fine. For example if i didn't call the function "dbtest(fname);", all the values in the .txt file is getting displayed.



Please suggest the solution.











 



6 Replies

  • mijex71989's avatar
    mijex71989
    Occasional Contributor
    Hello,



    The CurrentDriver property holds a reference to the last created DDTDriver object (in your script, it is Driver2). So, after you close Driver2, Driver2 no longer holds a reference to the driver and the error you mention occur. Use DDT.DriverByName instead:






    function dbtest(fname)

    {

    var f1name = "C:\\TestData\\" + fname + ".txt";


     



    // Creates the driver

    var Driver2 = DDT["CSVDriver"](f1name);

    // Iterates through records

    while (! Driver2["EOF"]() )

    {

    AppScriptDriver();

    Driver2["Next"]();

    }

    // Closing the driver

    DDT["CloseDriver"](Driver2["Name"]);

    }



    function DbMasterBatchController()

    {

    var Driver1;

    // Creates the driver

    Driver1 = DDT["CSVDriver"]("C:\\TestData\\MBA.txt");

    // Iterates through records

    while (! Driver1["EOF"]() )

    {

    fname = DDT["DriverByName"](Driver1["Name"])["Value"](1);

    dbtest(fname);

    Driver1["Next"]();

    }

    // Closing the driver

    DDT["CloseDriver"](Driver1["Name"]);

    Log["Warning"]("Driver closed");

    }


  • ZooZoo's avatar
    ZooZoo
    Occasional Contributor
    Thanks for your inputs......it is working fine now.
  • Hi 



         How shall i do script to insert /append the data into excel sheet.   I tried in below ways But I couldn't achive to get result. whenever type book= app. then excel error is getting dispalyed ask me to send report.  I type script only not even execute that function. Tell how to excel manipulation with examples.




    function adddataexcel()

    {

    // Launch Excel

    var app;

    var book;

    app= Sys["OleObject"]("Excel.Application");

    //var Excelsht = Sys["OleObject"]("Excel.sheet");

    // Make it visible

    app["Application"]["Visible"]=true;

    book = app.

    }


    adddataexcel(){ app; book;app= ["OleObject"]("Excel.Application");app["Application"]["Visible"]=;book = app.}
  • ZooZoo's avatar
    ZooZoo
    Occasional Contributor

    Hi,


    I want to make sure the given object is not exist in the screen.


    function Obj_VerifyExists()


    {


    var objObjectName = NameMapping["Sys"]["IEXPLORE"]["pageMiserBa"]["frameThisapp"]["frameMainframe"]["formTheform"]["Panel"]("buttonsDiv")["Button"]("AddBtn");


          if (objObjectName["Exists"] == true)


            Log["Message"]("Object is exist in the screen");


          else


            Log["Message"]("Object not exist in the screen")


    }


    If the object is exist the if part is working fine.



    If the given object is not exist it is not going to else part. It’s giving error and stopping the script while assigning the object name to the variable (Getting error in very first line). The given object is exist in object repository.



    Please suggest how to make sure the given object is not exist in the screen?


    Thanks,


    Lakshmi Priya