Forum Discussion

coffee's avatar
coffee
Contributor
8 years ago
Solved

VarArrayHighBound Method

Hi, I am trying to understand what the method VarArrayHighBound does. I found the documentation https://support.smartbear.com/viewarticle/86740/?q=VarArrayHighBound  and try this one (in Javascript...
  • HKosova's avatar
    HKosova
    8 years ago

    coffee wrote:

    I saw somewhere on this website this piece of codes

      ...
      // Call the function
      arr = TestedPage.QuerySelectorAll(CSSSelector);
      // Check the result
      cnt = BuiltIn.VarArrayHighBound(arr,1);
      ...

    I just want to understand what does cnt = BuiltIn.VarArrayHighBound(arr,1); do actually.  :smileyhappy:   Thank You.


    That example is not quite correct, we'll fix it. Thanks for the notice! The correct JavaScript and JScript code would be:

    // JavaScript
    arr = TestedPage.QuerySelectorAll(CSSSelector);
    if (arr.length > 0)
      // found
    else
      // not found
    // JScript
    arr = TestedPage.QuerySelectorAll(CSSSelector);
    arr = arr.toArray(); // convert the result to a native JScript array
    if (arr.length > 0) // found else // not found

    To answer the question about VarArrayHighBound, it is used in VBScript and DelphiScript code to determine the high bound of an array. It's an analog of VBScript's UBound function. VarArrayLowBound and VarArrayHighBound are used to determine the range of array indexes when you need to iterate through an array in VBScript or DelphiScript, because arrays in these languages do not necessarily use zero-based indexing.

     

    In JavaScript and JScript, you simply use arr.length.

     

    Hope this helps!