Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Last active January 26, 2023 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmplinshi/96da25a6e49d6907c9134117c3082f2b to your computer and use it in GitHub Desktop.
Save tmplinshi/96da25a6e49d6907c9134117c3082f2b to your computer and use it in GitHub Desktop.
Function Sort(strOrArray)
Static doc
Dim s$
If Not IsObject(doc) Then
Set doc = CreateObject("htmlfile")
doc.parentWindow.eval "function sort(s){ return s.split(',').sort() }"
End If
If IsArray(strOrArray) Then
s = Join(strOrArray, ",")
s = doc.parentWindow.eval("sort('" & s & "')")
Sort = Split(s, ",")
Else
Sort = doc.parentWindow.eval("sort('" & strOrArray & "')")
End If
End Function
' Debug.Print SortNumber("99,3,20")
' Debug.Print Join(SortNumber(Array(3, 20, 9, 1)), "/")
Function SortNumber(strOrArray)
Static doc
Dim s$
If Not IsObject(doc) Then
Set doc = CreateObject("htmlfile")
doc.parentWindow.eval "function sort(s){ return s.split(',').sort( function(a,b){return a-b} ) }"
End If
If IsArray(strOrArray) Then
s = Join(strOrArray, ",")
s = doc.parentWindow.eval("sort('" & s & "')")
SortNumber = Split(s, ",")
Else
SortNumber = doc.parentWindow.eval("sort('" & strOrArray & "')")
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment