Forum Discussion

salley's avatar
salley
Frequent Contributor
7 years ago
Solved

Help on looping through data array

Hello,
I need to iterate through the data and use them in username and password fields. user name a then password 100 ,, and then b 200. can somebody please look at my code and help please. thanks

Username Password
a|B|C 100|200|300

 

Set ObjExcelApp=Sys.OleObject("Excel.Application")
Set ObjWoorkBook=ObjExcelApp.Workbooks.Open("Path")
Set ObjWorkSheet=ObjWoorkBook.Sheets("Sheet1")
i=2
StrUname=trim(ObjWorkSheet.Cells(i,1))
StrPW=trim(ObjWorkSheet.Cells(i,2))
UArray=Split(StrClassCode,"|")
PArray=Split(strExposure,"|")

'I am just not sure how to loop through the data use them accordingly,,,,

For i=0 to Ubound(UArray)

for j=0 to UBound(PArray)
msgbox UArray(i)

MsgBox PArray(j)
Next
Next

  • I guess you can do like below,


    function CurDriverExample() { // Creates a driver DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1"); var colSkipper = 0; // Iterates through records while (! DDT.CurrentDriver.EOF()) { //Gets a value from the storage and posts it to the log for(var c = colSkipper ; c < DDT.CurrentDriver.ColumnCount ; c++){ Log.Message(DDT.CurrentDriver.Value(c)); } colSkipper++;//to skip one col in each row DDT.CurrentDriver.Next(); } // Closes the driver DDT.CloseDriver(DDT.CurrentDriver.Name); }

4 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    You need to create oleObject to use the excel [this way also we can do].

    TestComplete provides in-build function to access the excel data using DDT drivers.

     

    Example from Smartbear doc:

     

    function CurDriverExample()
    {
      // Creates a driver
      DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1");
       
      // Iterates through records
      while (! DDT.CurrentDriver.EOF())
      { 
      //Gets a value from the storage and posts it to the log
        Log.Message(DDT.CurrentDriver.Value(0)); 
        DDT.CurrentDriver.Next(); 
      }
      
      // Closes the driver
      DDT.CloseDriver(DDT.CurrentDriver.Name);
    }

     

    Ref;https://support.smartbear.com/testcomplete/docs/reference/program-objects/ddt/exceldriver.html

    • salley's avatar
      salley
      Frequent Contributor

      Thanks for the reply, I can read the data what's I'm having trouble is with when I'm trying to split the data from the cell and using it,, for ex, I need to split the data from col A and Col B then use it, first iteration item 1 from col A then item1 from Col b, second iteration item 2 from col A and then Item 2 from Col B and do some task,,,,,, and so on,, I'm having trouble with writing this statement in loop. thanks

      • shankar_r's avatar
        shankar_r
        Community Hero

        I guess you can do like below,


        function CurDriverExample() { // Creates a driver DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1"); var colSkipper = 0; // Iterates through records while (! DDT.CurrentDriver.EOF()) { //Gets a value from the storage and posts it to the log for(var c = colSkipper ; c < DDT.CurrentDriver.ColumnCount ; c++){ Log.Message(DDT.CurrentDriver.Value(c)); } colSkipper++;//to skip one col in each row DDT.CurrentDriver.Next(); } // Closes the driver DDT.CloseDriver(DDT.CurrentDriver.Name); }