I have a file we share among a lot of people at work. The past five years the code has worked fine, but now a new guy is introduced to the file and he get the (links to other threads about the error) automation error on this part below:
Dim TillfLevdagar(1 To 14) As String
....
' code that sets some of the array items above
.....
Dim arr2 As Object
Set arr2 = CreateObject("System.Collections.ArrayList") ' here it errors
For Each itm In TillfLevdagar
If itm <> "" Then arr2.Add CInt(itm)
Next
arr2.Sort
For Each itm In arr2
msg = msg & itm & ","
Next
Since this is a work computer we are very limited in allowing any software to be installed. That includes Microsoft software.
Becuase of this I ask what alternatives do I have to the code above?
CodePudding user response:
Please, try the next sorting way and use only the initial (TillfLevdagar
) array:
Sub BubbleSort(arr)
Dim i As Long, j As Long, temp
For i = LBound(arr) To UBound(arr) - 1
For j = i 1 To UBound(arr)
If arr(i) > arr(j) Then
temp = arr(i): arr(i) = arr(j)
arr(j) = temp
End If
Next j
Next i
End Sub
You can test it using the next testing procedure:
Sub testBubbleSort()
Dim arr, arrStr(1 To 14) As String, i As Long
arr = Split("test,boolean,core,leaf,dream,crises,bet,arrow", ",")
For i = 1 To 14
arrStr(i) = Chr(Int((25 1) * Rnd 1) 64) & "test"
Next i
BubbleSort arr
Debug.Print Join(arr, "|")
BubbleSort arrStr
Debug.Print Join(arrStr, "|")
End Sub
I have this sorting sub in my testing collection Subs, from some years. I do not remember where from I found it and what I adapted, if I did that. It is a simple sorting procedure. Anyhow, I used it many times with good results.