WriteByte Method

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

Description

Use the WriteByte method to convert the specified value to a byte value and to write it to a binary file. The value is written starting from the current position. If the position is not at the end of the file, the converted value overwrites the previous bytes.

Declaration

aqBinaryFileObj.WriteByte(Value)

aqBinaryFileObj An expression, variable or parameter that specifies a reference to an aqBinaryFile object
Value [in]    Required    Variant    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Value

Defines the variant-compatible value to be written to a file.

Result Value

True if the value has been written successfully, and False otherwise.

Remarks

On success, the cursor position is shifted by one byte.

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

Example

The following code converts an integer value to a byte value and write it at the end of a binary file.

JavaScript, JScript

function WritingByteToFile()
{
  MyFile=aqFile.OpenBinaryFile("C:\\MyFiles\\FileName.txt", 10)
  //Converting 65 to a byte value and writing it to the end of the file
  MyFile.WriteByte(65)
  MyFile.Close();
}

Python

def WritingByteToFile():
  MyFile = aqFile.OpenBinaryFile("C:\\MyFiles\\FileName.txt", 10)
  # Converting 65 to a byte value and writing it to the end of the file
  MyFile.WriteByte(65)
  MyFile.Close()

VBScript

Sub WritingByteToFile
  Set MyFile=aqFile.OpenBinaryFile("C:\MyFiles\FileName.txt", 10)
  ' Converting 65 to a byte value and writing it to the end of the file
  MyFile.WriteByte(65)
  MyFile.Close
End Sub

DelphiScript

procedure WritingByteToFile;
var MyFile: OleObject;
begin 
  MyFile:=aqFile.OpenBinaryFile('C:\MyFiles\FileName.txt', 10);
  //Converting 65 to a byte value and writing it to the end of the file
  MyFile.WriteByte(65);
  MyFile.Close();
end;

C++Script, C#Script

function WritingByteToFile()
{
  MyFile=aqFile["OpenBinaryFile"]("C:\\MyFiles\\FileName.txt", 10);
  //Converting 65 to a byte value and writing it to the end of the file
  MyFile["WriteByte"](65);
  MyFile["Close"]();
}

See Also

Working With Files From Scripts
ReadByte Method
WriteBytes Method

Highlight search results