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)
function abc () { var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}; x = BuiltIn.VarArrayHighBound (person, 1); Log.Message(x); }
TC returns
Error VarArrayHighBound Invalid argument
I don't quite understand how this method work.
Also, what is Dim? If I have 1 dimension array with 4 elements like my "var person" , then Dim should be "1" ? If I have 2 dimension array , then Dim should be "2" ? Thanks.
Dim The index of the array's dimension whose high bound you want to get. The leftmost dimension has index 1, the second dimension index is 2, etc.
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 foundTo 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!