SkipLine Method

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

Description

Use the SkipLine method to skip a given number of lines starting from the current position within a file.

Declaration

aqTextFileObj.SkipLine(LinesCount)

aqTextFileObj An expression, variable or parameter that specifies a reference to an aqTextFile object
LinesCount [in]    Required    Integer    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

LinesCount

Defines the number of lines to skip.

If LinesCount equals 0, then the cursor is moved to the beginning of the current line. If LinesCount is greater than 0, then the cursor is moved forward (to the end of the file). If LinesCount is less than 0, the cursor is moved backward (to the beginning of the file).

Result Value

True if the cursor position has changed, and False otherwise.

Remarks

On success, the cursor position is shifted to the beginning of the line that follows the skipped ones.

If the number of lines remaining in the file is less than the number specified by the LinesCount parameter, the method does nothing and returns False.

Example

The code below opens the specified file for both reading and writing, skips one line and then posts the string from the current cursor position to the test log.

JavaScript, JScript

function SkipLineExample()
{
  var sPath = "D:\\Files\\MyFile.txt";
  
  // Opens the specified file for reading and writing
  var myFile = aqFile.OpenTextFile(sPath, aqFile.faReadWrite, aqFile.ctANSI);
  
  // Writes data to the file
  myFile.WriteLine("Hello, world.");
  myFile.WriteLine("One more line.");
  
  myFile.SetPosition(0, 0);
  
  // Skips one line
  myFile.SkipLine(1);
  var Str = myFile.ReadString(8);
  // Posts the current symbol to the test log
  Log.Message(Str);
    
  // Closes the file and saves the changes
  myFile.Close();
}

Python

def SkipLineExample():
  sPath = "D:\\Files\\MyFile.txt"
  # Opens the specified file for reading and writing
  myFile = aqFile.OpenTextFile(sPath, aqFile.faReadWrite, aqFile.ctANSI)
  # Writes data to the file
  myFile.WriteLine("Hello, world.")
  myFile.WriteLine("One more line.")
  myFile.SetPosition(0, 0)
  # Skips one line
  myFile.SkipLine(1);
  Str = myFile.ReadString(8);
  # Posts the current symbol to the test log
  Log.Message(Str)
  # Closes the file and saves the changes
  myFile.Close()

VBScript

Sub SkipLineExample

  sPath = "D:\Files\MyFile.txt"
  
  ' Opens the specified file for reading and writing
  Set myFile = aqFile.OpenTextFile(sPath, aqFile.faReadWrite, aqFile.ctANSI)
  
  ' Writes data to the file
  myFile.WriteLine("Hello, world.")
  myFile.WriteLine("One more line.")
  
  Call myFile.SetPosition(0, 0)
  
  ' Skips one line
  myFile.SkipLine(1)
  Str = myFile.ReadString(8)
  ' Posts the current symbol to the test log
  Log.Message(Str)
    
  ' Closes the file and saves the changes
  myFile.Close
  
End Sub

DelphiScript

function SkipLineExample;
var sPath, myFile, Str;
begin
  sPath := 'D:\Files\MyFile.txt';
  
  // Opens the specified file for reading and writing
  myFile := aqFile.OpenTextFile(sPath, aqFile.faReadWrite, aqFile.ctANSI);
  
  // Writes data to the file
  myFile.WriteLine('Hello, world.');
  myFile.WriteLine('One more line.');
  
  myFile.SetPosition(0, 0);
  
  // Skips one line
  myFile.SkipLine(1);
  Str := myFile.ReadString(8);
  // Posts the current symbol to the test log
  Log.Message(Str);
    
  // Closes the file and saves the changes
  myFile.Close();
end;

C++Script, C#Script

function SkipLineExample()
{
  var sPath = "D:\\Files\\MyFile.txt";
  
  // Opens the specified file for reading and writing
  var myFile = aqFile["OpenTextFile"]( sPath, aqFile["faReadWrite"], aqFile["ctANSI"] );
  
  // Writes data to the file
  myFile["WriteLine"]("Hello, world.");
  myFile["WriteLine"]("One more line.");
  
  myFile["SetPosition"](0, 0);
  
  // Skips one line
  myFile["SkipLine"](1);
  var Str = myFile["ReadString"](8);
  // Posts the current symbol to the test log
  Log["Message"](Str);
    
  // Closes the file and saves the changes
  myFile["Close"]();
}

See Also

Working With Files From Scripts
Skip Method
SkipSpaces Method

Highlight search results