Platforms to show: All Mac Windows Linux Cross-Platform

Back to SortMBS module.

Previous items Next items

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:

SortMBS.SortMBS(extends theArray() as Double, descending as boolean = false)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sorts an array.
Example
// disable background threads, which would slow us down
#Pragma BackgroundTasks False

Var a(10000000) As Double
Var b(10000000) As Double
Var c(10000000) As Double

Var u As Integer = a.ubound
For i As Integer = 0 To u
Var n As Integer = i Mod 1000
a(i) = n
b(i) = n
c(i) = n

Next

Var m1 As Double = Microseconds
a.Sort
Var m2 As Double = Microseconds
b.SortMBS
Var m3 As Double = Microseconds
c.SortMBS True // reverse
Var m4 As Double = Microseconds

Var XojoSort As Double = (m2 - m1) / 1000.0 // e.g. 142
Var MBSSort As Double = (m3 - m2) / 1000.0 // e.g. 128
Var MBSSortReverse As Double = (m4 - m3) / 1000.0 // e.g. 120

MessageBox "Xojo: "+XojoSort.ToString+EndOfLine+"MBS Sort: "+MBSSort.ToString+EndOfLine+"MBS Sort reverse: "+MBSSortReverse.ToString
Break

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

See also:

Previous items Next items

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


The biggest plugin in space...