ReadShort Method

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

The ReadShort method retrieves two bytes from a binary file (starting from the current cursor position) and treats them as an integer value.

Declaration

aqBinaryFileObj.ReadShort()

aqBinaryFileObj An expression, variable or parameter that specifies a reference to an aqBinaryFile object
Result Integer

Applies To

The method is applied to the following object:

Result Value

The integer value read from the file.

Remarks

On success, the cursor position is shifted by 2 bytes.

Keep in mind that writing an integer value shifts the cursor position either by 4 or by 8 bytes, whereas reading an integer value can shift the position by 1-8 bytes depending on the method used.

Example

The code below demonstrates how to use the ReadShort method.

JavaScript, JScript

function ReadingDataFromBinaryFile()
{
 Path = "C:\\MyFiles\\FileName.txt";
 
 // Creates a new file and opens it for writing in binary mode
 myFile = aqFile.OpenBinaryFile(Path, aqFile.faWrite, true);
 
 // Writes data to the file
  myFile.Write(152);
 
 // Closes the file
 myFile.Close();
 
 // Opens the file for reading
 myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead);
 
 // Reads data from the file
 Log.Message(myFile.ReadShort());
  
 // Closes the file
 myFile.Close();
}

Python

def ReadingDataFromBinaryFile():
  Path = "C:\\MyFiles\\FileName.txt"
  # Creates a new file and opens it for writing in binary mode
  myFile = aqFile.OpenBinaryFile(Path, aqFile.faWrite, True)
  # Writes data to the file
  myFile.Write(152)
  # Closes the file
  myFile.Close()
  # Opens the file for reading
  myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead)
  # Reads data from the file 
  Log.Message(myFile.ReadShort())
  # Closes the file
  myFile.Close()

VBScript

Sub ReadingDataFromBinaryFile()
Dim Path, myFile
 'Set Path = "C:\MyFiles\FileName.txt"
 
 ' Creates a new file and opens it for writing in binary mode
 Set myFile = aqFile.OpenBinaryFile("C:\MyFiles\FileName.txt", aqFile.faWrite, true)
 
 ' Writes data to the file
  Call myFile.Write(152)
 
 ' Closes the file
 Call myFile.Close()
 
 ' Opens the file for reading
 Set myFile = aqFile.OpenBinaryFile("C:\MyFiles\FileName.txt", aqFile.faRead)
 
 ' Reads data from the file
  Call Log.Message(aqConvert.IntToStr(myFile.ReadShort))
 
 ' Closes the file
 Call myFile.Close()
End Sub

DelphiScript

procedure ReadingDataFromBinaryFile;
var Path, myFile: OleObject;
begin
 Path := 'C:\MyFiles\FileName.txt';
 
 // Creates a new file and opens it for writing in binary mode
 myFile := aqFile.OpenBinaryFile(Path, aqFile.faWrite, true);
 
 // Writes data to the file
 myFile.Write(152);
 
 // Closes the file
 myFile.Close();
 
 // Opens the file for reading
 myFile := aqFile.OpenBinaryFile(Path, aqFile.faRead);
 
 // Reads data from the file
 Log.Message(aqConvert.IntToStr(myFile.ReadShort()));
  
 // Closes the file
 myFile.Close();
end;

C++Script, C#Script

function ReadingDataFromBinaryFile()
{
 Path = "C:\\MyFiles\\FileName.txt";
 
 // Creates a new file and opens it for writing in binary mode
 myFile = aqFile["OpenBinaryFile"](Path, aqFile.faWrite, true);
 
 // Writes data to the file
 myFile["Write"](152);

 // Closes the file
 myFile["Close"]();
 
 // Opens the file for reading
 myFile = aqFile["OpenBinaryFile"](Path, aqFile.faRead);
 
 // Reads data from the file
 Log["Message"]( "The bolean is: "+ myFile["ReadShort"]() );
  
 // Closes the file
 myFile["Close"]();
}

See Also

Working With Files From Scripts
WriteShort Method
ReadInt Method
ReadByte Method
ReadBytes Method
ReadCurrency Method
ReadInt64 Method
ReadFloat Method
ReadString Method
ReadBool Method
ReadDate Method

Highlight search results