I like to use dictionary for these things
Here is my 2 ¢
Option Explicit
' based on original code from here:
' http://support.microsoft.com/default.aspx?scid=kb;en-us;246067
' request reference to Microsoft Scripting Runtime
Dim d, i
Const dictKey = 1
Const dictItem = 2
Function SortDictionary(objDict, intSort)
' declare our variables
Dim strDict()
Dim objKey
Dim strKey, strItem
Dim X, Y, Z
' get the dictionary count
Z = objDict.Count
' we need more than one item to warrant sorting
If Z > 1 Then
' create an array to store dictionary information
ReDim strDict(Z, 2)
X = 0
' populate the string array
For Each objKey In objDict
strDict(X, dictKey) = CStr(objKey)
strDict(X, dictItem) = CStr(objDict(objKey))
X = X + 1
Next
' perform a a shell sort of the string array
For X = 0 To (Z - 2)
For Y = X To (Z - 1)
If StrComp(strDict(X, intSort), strDict(Y, intSort), vbTextCompare) > 0 Then
strKey = strDict(X, dictKey)
strItem = strDict(X, dictItem)
strDict(X, dictKey) = strDict(Y, dictKey)
strDict(X, dictItem) = strDict(Y, dictItem)
strDict(Y, dictKey) = strKey
strDict(Y, dictItem) = strItem
End If
Next
Next
' erase the contents of the dictionary object
objDict.RemoveAll
' repopulate the dictionary with the sorted information
For X = 0 To (Z - 1)
objDict.Add strDict(X, dictKey), strDict(X, dictItem)
Next
End If
End Function
Sub NextLayerByAscending()
Dim oLayer As AcadLayer
Dim n
Set d = CreateObject("Scripting.Dictionary")
For Each oLayer In ThisDrawing.Layers
If oLayer.Name Like "SOL-SECT#-VIS" Or _
oLayer.Name Like "SOL-SECT##-VIS" Then
d.Add CStr(n), oLayer.Name
n = n + 1
End If
Next
SortDictionary d, dictItem
Dim lastLay As String, nextLay As String
lastLay = "SOL-SECT12-VIS" 'dummy layers for debug
For Each i In d
If d(i) > lastLay Then
nextLay = d(i)
Exit For
End If
Next
MsgBox "Next layer is: " & Chr(34) & nextLay & Chr(34)
End Sub
~'J'~