DriveMethod Method

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Use this method to iterate through records of the data storage to which the ProgObj driver provides access and process each record with the script routine specified by the method parameter. To address the driver within this routine, you can use the DDT.CurrentDriver property. See Using DDT Drivers for more information.

Declaration

ProgObj.DriveMethod(Name)

ProgObj An expression, variable or parameter that specifies a reference to one of the objects listed in the Applies To section
Name [in]    Required    String    
Result None

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Name

Specifies the name of the script routine that will be executed for each record of the data storage to which ProgObj provides access.

The name should be specified in format unit_name.routine_name. There is no need to include the specified unit in the uses (USEUNIT) clause of the unit where DriveMethod is called. The specified routine should not use any parameters.

Result Value

None.

Remarks

The method does not work in Script Extensions.

Example

The following code sample illustrates how to use the method:

JavaScript, JScript

var RecNo;
  
// Posts data to the log (helper routine)
function ProcessData()
{
  var Fldr, i;
  
  Fldr = Log.CreateFolder("Record: " + aqConvert.VarToStr(RecNo));
  Log.PushLogFolder(Fldr);
  
  for(i = 0; i < DDT.CurrentDriver.ColumnCount; i++)
    Log.Message(DDT.CurrentDriver.ColumnName(i) + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value(i)));
  
  Log.PopLogFolder();
  RecNo = RecNo + 1;
}
  
// Creates the driver (main routine)
function TestDriver()
{
  var Driver;
  
  // Creates the driver
  // If you connect to an Excel 2007 sheet, use the following method call:
  // Driver = DDT.ExcelDriver("C:\\MyFile.xlsx", "Sheet1", true);
  Driver = DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1");
  
  // Iterates through records
  RecNo = 0;
  Driver.DriveMethod("Unit1.ProcessData")
  
  // Closing the driver
  DDT.CloseDriver(Driver.Name);
}

Python

# Global variable for record numbers
RecNo = 0

# Posts data to the log (helper routine)
def ProcessData():
  global RecNo
  Fldr = Log.CreateFolder("Record: " + aqConvert.VarToStr(RecNo))
  Log.PushLogFolder(Fldr)
  for i in range(0, DDT.CurrentDriver.ColumnCount):
    Log.Message(str(DDT.CurrentDriver.ColumnName[i]) + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value[i]))
  Log.PopLogFolder() 
  RecNo = RecNo + 1

# Creates the driver (main routine) 
def TestDriver():
  # Creates the driver 
  # If you connect to an Excel 2007 sheet, use the following method call: 
  # Driver = DDT.ExcelDriver("C:\\MyFiles\\MyFile.xlsx", "Sheet1", True) 
  Driver = DDT.ExcelDriver("C:\\MyFiles\\MyFile.xls", "Sheet1")
  # Iterates through records 
  Driver.DriveMethod("UnitName.ProcessData")
  # Closing the driver 
  DDT.CloseDriver(Driver.Name)

VBScript

Dim RecNo
  
' Posts data to the log (helper routine)
Sub ProcessData
  Dim Fldr, i
  
  Fldr = Log.CreateFolder("Record: " + aqConvert.VarToStr(RecNo))
  Log.PushLogFolder Fldr
  
  For i = 0 To DDT.CurrentDriver.ColumnCount - 1
    Log.Message DDT.CurrentDriver.ColumnName(i) + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value(i))
  Next
  
  Log.PopLogFolder
  RecNo = RecNo + 1
End Sub
  
' Creates the driver (main routine)
Sub TestDriver
  Dim Driver
  
  ' Creates the driver
  ' If you connect to an Excel 2007 sheet, use the following method call:
  ' Set Driver = DDT.ExcelDriver("C:\MyFile.xlsx", "Sheet1", True)
  Set Driver = DDT.ExcelDriver("C:\MyFile.xls", "Sheet1")
  
  ' Iterates through records
  RecNo = 0
  Driver.DriveMethod "Unit1.ProcessData"
  
  ' Closing the driver
  Call DDT.CloseDriver(Driver.Name)
End Sub

DelphiScript

var RecNo;
  
  
// Posts data to the log (helper routine)
procedure ProcessData;
var
  Fldr, i : OleVariant;
begin
  Fldr := Log.CreateFolder('Record: ' + aqConvert.VarToStr(RecNo));
  Log.PushLogFolder(Fldr);
  
  for i := 0 to DDT.CurrentDriver.ColumnCount - 1 do
    Log.Message(DDT.CurrentDriver.ColumnName[i] + ': ' + aqConvert.VarToStr(DDT.CurrentDriver.Value[i]));
  
  Log.PopLogFolder;
  RecNo := RecNo + 1;
end;
  
  // Creates the driver (main routine)
procedure TestDriver;
var
  Driver : OleVariant;
begin
  // Creates the driver
  // If you connect to an Excel 2007 sheet, use the following method call:
  // Driver := DDT.ExcelDriver('C:\MyFile.xlsx', 'Sheet1', True);
  Driver := DDT.ExcelDriver('C:\MyFile.xls', 'Sheet1');
  
  // Iterates through records
  RecNo := 0;
  Driver.DriveMethod('Unit1.ProcessData');
  
  // Closing the driver
  DDT.CloseDriver(Driver.Name);
end;

C++Script, C#Script

var RecNo;
  
// Posts data to the log (helper routine)
function ProcessData()
{
  var Fldr, i;
  
  Fldr = Log["CreateFolder"]("Record: " + aqConvert.VarToStr(RecNo));
  Log["PushLogFolder"](Fldr);
  
  for(i = 0; i < DDT["CurrentDriver"]["ColumnCount"]; i++)
    Log.Message(DDT["CurrentDriver"]["ColumnName"](i) + ": " + aqConvert.VarToStr(DDT["CurrentDriver"]["Value"](i)));
  
  Log["PopLogFolder"]();
  RecNo = RecNo + 1;
}
  
// Creates the driver (main routine)
function TestDriver()
{
  var Driver;
  
  // Creates the driver
  // If you connect to an Excel 2007 sheet, use the following method call:
  // Driver = DDT["ExcelDriver"]("C:\\MyFile.xlsx", "Sheet1", true);
  Driver = DDT["ExcelDriver"]("C:\\MyFile.xls", "Sheet1");
  
  // Iterates through records
  RecNo = 0;
  Driver["DriveMethod"]("Unit1.ProcessData");
  
  // Closing the driver
  DDT["CloseDriver"](Driver["Name"]);
}

See Also

Using DDT Drivers
EOF Method
Next Method
CurrentDriver Property

Highlight search results