CorArray: TrueForAll |
Determines whether every element in the array matches the conditions defined by the specified callback method.
Public Function TrueForAll( ByRef Arr As Variant, ByVal AddressOfPredicate As Long ) As Boolean
The AddressOfPredicate is an address to a method that returns True if the value passed to it matches the conditions defined in the callback method. The elements of Arr are individually passed to the callback method, and processing is stopped when the method returns False for any element.
The callback method should have a signature resembling the following:
Public Function CallbackMethod(ByRef Value As <Type>) As Boolean ' Evaluate value End Function
It has one parameter that is defined as ByRef and should be the same type as the elements in the array to be searched.
It is extremely important to define the callback method correctly. If the method is incorrect, the application may crash.
Exception | Conditioni |
---|---|
ArgumentNullException | Arr is uninitialized |
RankException | Arr has more than one dimension. |
The following code example checks two arrays for containing only ages 18 or older.
Private Sub Main() Dim Adults() As Long Dim Mixed() As Long Adults = NewLongs(22, 45, 37, 62, 18) Mixed = NewLongs(29, 33, 16, 49, 13) Debug.Print "Adults array has only adults:" Debug.Print CorArray.TrueForAll(Adults, AddressOf Age18OrOlder) Debug.Print t("\nMixed array has only adults:") Debug.Print CorArray.TrueForAll(Mixed, AddressOf Age18OrOlder) End Sub ' The method accepts a ByRef parameter of the array element type. Private Function Age18OrOlder(ByRef Age As Long) As Boolean Age18OrOlder = Age >= 18 End Function ' This code example produces the following output. ' Adults array has only adults: ' True ' ' Mixed array has only adults: ' False