aqBytes Object

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

Description

The aqBytes object represents a sequence of bytes. You get the object in tests by using the aqBinaryFile.ReadBytes method. Using the properties and methods of the aqBytes object you can read and write an individual byte of the sequence.

Members

Example

The example below demonstrates how you can use the aqBytes object to work with a byte sequence.

JavaScript, JScript

function ArrayItems()
{
  Path = "C:\MyFiles\FileName.txt";
  
  // Opens the specified file for reading in the binary mode
  myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead);
  
  // Reads bytes from the file
  readBytes = myFile.ReadBytes();
  
  // Obtains the number of items in the array returned by ReadBytes()
  countBytes = readBytes.Count;
  
  // Iterates through the items
  for (var i = 0; i < countBytes; i++)
  {
    // Obtains the current item
    var Item = readBytes.Item(i);
    
    // Posts the item to the test log
    Log.Message("The current item: " + Item);
  }
  myFile.Close();
}

Python

def ArrayItems():
   Path = "C:\\MyFiles\FileName.txt"
   
   # Opens the specified file for reading in the binary mode
   myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead)
   
   # Reads bytes from the file
   readBytes = myFile.ReadBytes()
   
   # Obtains the number of items in the array returned by ReadBytes()
   countBytes = readBytes.Count
   
   # Iterates through the items
   for i in range(0, countBytes):
     # Obtains the current item
     Item = readBytes.Item[i]
     # Posts the item to the test log
     Log.Message("The current item: " + aqConvert.VarToStr(Item))
   
   myFile.Close()

VBScript

Sub ArrayItems
Dim Path, myFile, readBytes, countBytes, Item

   Path = "C:\\MyFiles\FileName.txt"
   
   ' Opens the specified file for reading in the binary mode
   Set myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead)
   
   ' Reads bytes from the file
   Set readBytes = myFile.ReadBytes()
   
   ' Obtains the number of items in the array returned by ReadBytes()
   countBytes = readBytes.Count
   
   ' Iterates through the items
   For i = 0 to (countBytes - 1)
     ' Obtains the current item
     Item = readBytes.Item(i)
     ' Posts the item to the test log
     Log.Message("The current item: " + aqConvert.VarToStr(Item))
   Next
   
   Call myFile.Close()
End Sub

DelphiScript

procedure ArrayItems;
var Path, myFile, readBytes, countBytes, Item, i;
begin
  Path := 'C:\MyFiles\FileName.txt';
  
  // Opens the specified file for reading in the binary mode
  myFile := aqFile.OpenBinaryFile(Path, aqFile.faRead);
  
  // Reads bytes from the file
  readBytes := myFile.ReadBytes();
  
  // Obtains the number of items in the array returned by ReadBytes()
  countBytes := readBytes.Count;
  
  // Iterates through the items
  for i := 0 to (countBytes - 1) do
  begin
    // Obtains the current item
    Item := readBytes.Item[i];
    // Posts the item to the test log
    Log.Message('The current item: ' + aqConvert.VarToStr(Item));
  end;
  myFile.Close();
end;

C++Script, C#Script

function ArrayItems()
 {
   Path = "C:\\MyFiles\\FileName.txt";
   
   // Opens the specified file for reading in the binary mode
   myFile = aqFile["OpenBinaryFile"](Path, aqFile["faRead"]);
   
   // Reads bytes from the file
   readBytes = myFile["ReadBytes"]();
   
   // Obtains the number of items in the array returned by ReadBytes()
   countBytes = readBytes["Count"];
   
   // Iterates through the items
   for (var i = 0; i < countBytes; i++)
   {
     // Obtains the current item
     var Item = readBytes["Item"](i);
     // Posts the item to the test log
     Log["Message"]("The current item: " + aqConvert["VarToStr"](Item));
   }
   myFile["Close"]();
 }

See Also

aqBinaryFile Object
ReadBytes Method
WriteBytes Method

Highlight search results