Item Property

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

Description

Use the aqBytesObj.Item property to get the byte specified by its index in the given byte sequence returned by the aqBytes object. To learn the length of the byte sequence, use the Count property.

Declaration

aqBytesObj.Item(Index)

Read-Write Property Integer
aqBytesObj An expression, variable or parameter that specifies a reference to an aqBytes object
Index [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

The index of the desired byte in the sequence. The index ranges between 0 and aqBytes.Count - 1.

Property Value

An integer that represents the desired byte.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the Item property in square brackets: Item[Index].

Example

The code below gets binary data from a file. After that, the routine iterates through the obtained sequence and posts each byte to the test log.

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

aqBytes Object
Count Property
SetItem Method

Highlight search results