Close Method

Applies to TestComplete 14.50, last modified on April 22, 2021

Description

The Close method closes the text file to which the aqTextFileObj object relates. If the file was opened for writing, the method saves all the changes that were made.

Declaration

aqTextFileObj.Close()

aqTextFileObj An expression, variable or parameter that specifies a reference to an aqTextFile object
Result Boolean

Applies To

The method is applied to the following object:

Result Value

True if the file was closed successfully, and False otherwise.

Example

The code below opens the specified file for writing, adds some text to the file and then closes it saving all the changes.

JavaScript, JScript

function CloseFile()
{
  var sPath = "D:\\Files\\MyFile.txt";
  
  // Opens the specified file for writing
  var myFile = aqFile.OpenTextFile(sPath, aqFile.faWrite, aqFile.ctANSI);
  // Writes text to the file
  myFile.Write("Hello, world.");
  
  // Closes the file and saves the changes
  myFile.Close();
}

Python

def CloseFile():
  sPath = "D:\\Files\\MyFile.txt"
  # Opens the specified file for writing
  myFile = aqFile.OpenTextFile(sPath, aqFile.faWrite, aqFile.ctANSI)
  # Writes text to the file
  myFile.Write("Hello, world.")
  # Closes the file and saves the changes
  myFile.Close()

VBScript

Sub CloseFile

  sPath = "D:\Files\MyFile.txt"
  
  ' Opens the specified file for writing
  Set myFile = aqFile.OpenTextFile(sPath, aqFile.faWrite, aqFile.ctANSI)
  ' Writes text to the file
  myFile.Write("Hello, world.")
  
  ' Closes the file and saves the changes
  myFile.Close
  
End Sub

DelphiScript

function CloseFile;
var sPath, myFile;
begin
  sPath := 'D:\Files\MyFile.txt';
  
  // Opens the specified file for writing
  myFile := aqFile.OpenTextFile(sPath, aqFile.faWrite, aqFile.ctANSI);
  // Writes text to the file
  myFile.Write('Hello, world.');
  
  // Closes the file and saves the changes
  myFile.Close();
end;

C++Script, C#Script

function CloseFile()
{
  var sPath = "D:\\Files\\MyFile.txt";
  
  // Opens the specified file for writing
  var myFile = aqFile["OpenTextFile"]( sPath, aqFile["faWrite"], aqFile["ctANSI"] );
  // Writes text to the file
  myFile["Write"]("Hello, world.");
  
  // Closes the file and saves the changes
  myFile["Close"]();
}

See Also

Working With Files From Scripts
OpenTextFile Method

Highlight search results