Platforms to show: All Mac Windows Linux Cross-Platform

Back to SortMBS module.

SortMBS.SortArrayMBS(theArray() as DateTime, descending as boolean = false)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sorts a DateTime array.
Example
Var test() As DateTime
test.Append DateTime.Now
test.Append DateTime.FromString("2011-04-24")
test.Append DateTime.FromString("2022-03-21")
test.Append DateTime.FromString("2033-10-10")

SortArrayMBS test

Break // see in debugger

// now reverse it
SortArrayMBS test, True

Break // see in debugger

Does nothing for arrays with theArray.count < 2.
Pass true for descending to reverse the order.

See also:

SortMBS.SortArrayMBS(theArray() as Int64, theDelegate as SortVariantDelegateInt64MBS, descending as boolean = false)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sorts an Int64 array using a delegate to compare.
Example
Public Function CompareNumber(v1 as Integer, v2 as Integer) As integer
// we compare the absolute values, so 3 and -3 are next to each other in the result
v1 = Abs(v1)
v2 = Abs(v2)

If v1 = v2 Then
Return 0
ElseIf v1 < v2 Then
Return -1
Else
Return 1
End If
End Function

Sub Test
Var testInteger() As Integer = Array(1,3,6,1,2,-3,0,9)
SortArrayMBS testInteger, AddressOf CompareNumber

Break // see in debugger
End Sub

Does nothing for arrays with theArray.count < 2.
Pass true for descending to reverse the order.

Your delegate should be fast and return 0 if both values are equal, 1 if first value is bigger or -1 if first value is smaller.

See also:

SortMBS.SortArrayMBS(theArray() as Ptr, theDelegate as SortVariantDelegatePtrMBS, descending as boolean = false)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sorts a Ptr array using a delegate to compare.

Does nothing for arrays with theArray.count < 2.
Pass true for descending to reverse the order.

Your delegate should be fast and return 0 if both values are equal, 1 if first value is bigger or -1 if first value is smaller.

See also:

SortMBS.SortArrayMBS(theArray() as String, theDelegate as SortVariantDelegateStringMBS, descending as boolean = false)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sorts a string array using a delegate to compare.
Example
Public Function CompareString2ndWord(s1 as string, s2 as string) As integer
// sort by second word

s1 = s1.NthField(" ",2)
s2 = s2.NthField(" ",2)

Return s1.Compare(s2)
End Function

Sub Test
Var testString() As String = Array("Hello World", "Hallo Leute", "World Test", "First Entry", "abc def", "abc xyz")
SortArrayMBS testString, AddressOf CompareString2ndWord

Break // see in debugger
End Sub

Does nothing for arrays with theArray.count < 2.
Pass true for descending to reverse the order.

Your delegate should be fast and return 0 if both values are equal, 1 if first value is bigger or -1 if first value is smaller.

See also:

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...