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
Dim 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
Dim 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
Dim 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.SumArrayMBS(source() as Currency, sourceIndex as Integer = 0, sourceCount as Integer = -2, CheckOverflow as Boolean = false) as Currency

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sums up all the numbers in the array.
Example
Dim v() As Currency

// just sum up some currency values
v.Add 123.4567
v.Add 1
v.add 0
v.add -56
v.add 4567

Dim m1 As Double = Microseconds
Dim sum1 As Currency = SumArrayMBS(v, True)
Dim m2 As Double = Microseconds
Dim sum2 As Currency = SumArrayMBS(v, False)
Dim m3 As Double = Microseconds

Dim d1 As Double = m2-m1
Dim d2 As Double = m3-m2
// overflow checking can make it 100 times slower

// try to cause an overflow with huge numbers
v.add 100000000000000.0000
v.add 200000000000000.0000
v.add 300000000000000.0000
v.add 400000000000000.0000

Dim sum3 As Currency = SumArrayMBS(v, False)
Dim sum4 As Currency = SumArrayMBS(v, True)

Break

You can limit range by passing in a source index and source count.
If sourceCount is -2, we sum up whole array - sourceIndex.
Pass true for overflow check to detect overflows for each addition. Otherwise pass false for better performance.
Returns the sum of all values.

See also:

SortMBS.SumArrayMBS(source() as Double, sourceIndex as Integer = 0, sourceCount as Integer = -2) as Double

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sums up all the numbers in the array.
Example
Const u = 99999
Dim v(u) As Double

For i As Integer = 0 To u
v(i) = i
Next

Dim m1 As Double = Microseconds
Dim sumPlugin As Int64 = SumArrayMBS(v)
Dim m2 As Double = Microseconds
Dim sumXojo As Double
For i As Integer = 0 To u
sumXojo = sumXojo + v(i)
next
Dim m3 As Double = Microseconds

Dim timePlugin As Double = m2-m1
Dim timeXojo As Double = m3-m2
// plugin is faster than Xojo code

Break

You can limit range by passing in a source index and source count.
If sourceCount is -2, we sum up whole array - sourceIndex.
Returns the sum of all values.

See also:

SortMBS.SumArrayMBS(source() as Int64, sourceIndex as Integer = 0, sourceCount as Integer = -2, CheckOverflow as Boolean = false) as Int64

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sums up all the numbers in the array.
Example
Dim v() As Int64

// just sum up some currency values
v.Add 1234567
v.Add 1
v.add 0
v.add -56
v.add 4567

Dim m1 As Double = Microseconds
Dim sum1 As Int64 = SumArrayMBS(v, True)
Dim m2 As Double = Microseconds
Dim sum2 As Int64 = SumArrayMBS(v, False)
Dim m3 As Double = Microseconds

Dim d1 As Double = m2-m1
Dim d2 As Double = m3-m2
// overflow checking can make it 100 times slower

// try to cause an overflow with huge numbers
v.add 1000000000000000000
v.add 2000000000000000000
v.add 3000000000000000000
v.add 4000000000000000000

Dim sum3 As Int64 = SumArrayMBS(v, False)
Dim sum4 As Int64 = SumArrayMBS(v, True)

Break

You can limit range by passing in a source index and source count.
If sourceCount is -2, we sum up whole array - sourceIndex.
Pass true for overflow check to detect overflows for each addition. Otherwise pass false for better performance.
Returns the sum of all values.

See also:

Previous items Next items

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


The biggest plugin in space...