Description
Use the SetPosition method to move the cursor position to the desired line and column.
Declaration
aqTextFileObj.SetPosition(Line, Column)
| aqTextFileObj | An expression, variable or parameter that specifies a reference to an aqTextFile object | |||
| Line | [in] | Required | Integer | |
| Column | [in] | Required | Integer | |
| Result | Boolean | |||
Applies To
The method is applied to the following object:
Parameters
The method has the following parameters:
Line
Specifies the number of the desired line (numbering starts from zero).
Column
Specifies the number of the desired column (numbering starts from zero).
Result Value
True if the cursor position has changed, and False otherwise.
Example
The code below reads the specified file by lines and posts these lines to the test log.
JavaScript, JScript
function ReadTextFromFile()
						{
  var sPath = "D:\\Files\\MyFile.txt";
  // Creates a text file at the specified location 
  aqFile.Create(sPath);
  // Opens the created file for reading 
  var myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI);
  myFile.SetPosition(0, 0);
  
  // Obtains the total number of lines in the file
  var lNum = myFile.LinesCount;
  
  for (var i = 0; i < lNum; i++)
  {
    // Obtains the current line's length
    var lLength = myFile.LineLength(i);
    // Reads the current line 
    var Line = myFile.ReadString(lLength);
    // Sets the cursor to the next line
    myFile.SetPosition(i+1, 0);
    // Posts the current line to the test log
    Log.Message(Line);
  }
  
  // Closes the file 
  myFile.Close();
						}
Python
def ReadTextFromFile():
  sPath = "D:\\Files\\MyFile.txt"
  # Creates a text file at the specified location 
  aqFile.Create(sPath)
  # Opens the created file for reading 
  myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI)
  myFile.SetPosition(0, 0)
  # Obtains the total number of lines in the file
  lNum = myFile.LinesCount
  for i in range(0, lNum):
    # Obtains the current line's length
    lLength = myFile.LineLength(i)
    # Reads the current line 
    Line = myFile.ReadString(lLength);
    # Sets the cursor to the next line
    myFile.SetPosition(i+1, 0)
    #  Posts the current line to the test log
    Log.Message(Line)
  # Closes the file 
  myFile.Close()
VBScript
Sub ReadTextFromFile
  Dim sPath
  sPath = "D:\Files\MyFile.txt"
  ' Creates a text file at the specified location 
  aqFile.Create(sPath)
  ' Opens the created file for reading 
  Set myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI)
  Call myFile.SetPosition(0, 0)
  
  ' Obtains the total number of lines in the file
  lNum = myFile.LinesCount
  
  For i = 0 to lNum-1
    ' Obtains the current line's length
    lLength = myFile.LineLength(i) 
    ' Reads the current line 
    Line = myFile.ReadString(lLength)
    ' Sets the cursor to the next line
    Call myFile.SetPosition(i+1, 0)
    ' Posts the current line to the test log
    Log.Message(Line)
  Next
  
  ' Closes the file 
  Call myFile.Close()
End Sub 
DelphiScript
function ReadTextFromFile;
var sPath, myFile, lNum, i, lLength, Line;
begin
  sPath := 'D:\Files\MyFile.txt';
  // Creates a text file at the specified location 
  aqFile.Create(sPath);
  // Opens the created file for reading 
  myFile := aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI);
  myFile.SetPosition(0, 0);
  
  // Obtains the total number of lines in the file
  lNum := myFile.LinesCount;
  
  for i := 0 to lNum-1 do
  begin
    // Obtains the current line's length
    lLength := myFile.LineLength(i);
    // Reads the current line 
    Line := myFile.ReadString(lLength);
    // Sets the cursor to the next line
    myFile.SetPosition(i+1, 0);
    // Posts the current line to the test log
    Log.Message(Line);
  end;
  
  // Closes the file 
  myFile.Close();
end;
C++Script, C#Script
function ReadTextFromFile()
						{
  var sPath = "D:\\Files\\MyFile.txt";
  // Creates a text file at the specified location 
  aqFile["Create"](sPath);
  // Opens the created file for reading 
  var myFile = aqFile["OpenTextFile"](sPath, aqFile.faRead, aqFile.ctANSI);
  myFile["SetPosition"](0, 0);
  
  // Obtains the total number of lines in the file
  var lNum = myFile["LinesCount"];
  
  for (var i = 0; i < lNum; i++)
  {
    // Obtains the current line's length
    var lLength = myFile["LineLength"](i);
    // Reads the current line 
    var Line = myFile["ReadString"](lLength);
    // Sets the cursor to the next line
    myFile["SetPosition"](i+1, 0);
    // Posts the current line to the test log
    Log["Message"](Line);
  }
  
  // Closes the file 
  myFile["Close"]();
						}
See Also
Working With Files From Scripts
Cursor Property
Line Property
Column Property
