1

You can use UBound to determine the size of an array. I want to that that to an array returned as a result of a function, but then I get the error Invalid procedure call. This is the (simplified) function:

Public Function GetCheckBlocks(fileName)
    Dim counter, checkBlocks
    Set checkBlocks = CreateObject( "System.Collections.ArrayList" )

    For counter = 0 To 10
      checkBlocks.Add counter
    Next

    Set GetCheckBlocks = checkBlocks
End Function

And here is the way I call the function and want to get the size of the array:

Dim expectedChecks, expectedFile
expectedFile = "test.txt"

Set expectedChecks = GetCheckBlocks(expectedFile)
MsgBox UBound(expectedChecks)

What is wrong here and how do I get the size of the returned array?

1 Answer 1

1

Your function returns an ArrayList object, not an array. UBound only works with arrays. To get the number of elements contained in an ArrayList, use the .Count property:

expectedChecks.Count
Sign up to request clarification or add additional context in comments.

1 Comment

Alternatively: have the function return checkBlocks.ToArray if you want/need a VBScript array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.