Macros/ScriptForge/HowToSortArrayQuickwin
Appearance
< Macros | ScriptForge
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
These are short snippets for easy insertion in user's code of powerful functions.
- The loading of the ScriptForge Basic library is presumed done elsewhere.
- All used variables are declared explicitly.
- The concerned code is presented inside a BASIC function and/or a Python def. They may contain alternative syntaxes or options.
- Copy/paste what is useful to you.
How to sort an array
Authored 5 days ago by Jean-Pierre Ledure.
REM How to sort an array ?
REM Minimal required version: LibreOffice 7.6
REM Used service(s) Array
Sub sortarray()
Dim vector() As Variant
Dim sortedvector() As Variant
Dim arr As Object
GlobalScope.BasicLibraries.loadLibrary("ScriptForge") ' To be done once during the LO session
arr = CreateScriptService("Array")
vector = Array("X", "B", "h", "Z", "d")
' Default arguments: sortorder := "ASC", casesensitive := False
sortedvector = arr.Sort(vector, sortorder := "DESC", casesensitive := True) ' Lower case precede upper case
MsgBox Join(sortedvector, Chr(10))
End Sub