WriteShort Method

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

The WriteShort method writes an integer value to a binary file.

Declaration

aqBinaryFileObj.WriteShort()

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 to write to a file.

Remarks

  • On success, the cursor position is shifted by the length of the written data.

  • To use this method, you should open the needed file with the faWrite or faReadWrite access permission. See the description of the OpenBinaryFile method.

Example

The code below demonstrates how to use the WriteShort 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.WriteShort(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.WriteShort(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.WriteShort(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["WriteShort"](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
ReadShort Method
WriteInt Method
WriteByte Method
WriteBytes Method
WriteCurrency Method
WriteInt64 Method
WriteFloat Method
WriteString Method
WriteBool Method
WriteDate Method

Highlight search results