LO macros support collection objects. They are versatile objects, but very little documentation is found on the internet. Why ?
An alternative is to use subroutines in Python or java, or javascript. But who wants to stay in Basic? Why so little online support?
This test code describes some basic operation
Dim t As New Collection
dim a(2) as integer
a(0)=10:a(1)=20: tc=thisComponent
t.Add("fx", "x") ' adding string with key "x"
t.Add("fy", "y")
t.Add("fz", "z")
t.Add(a, "k")
s1=t("k")(0) ' extract array a from item "k" of test, read element 0
t.Add(tc, "tc")
s2=t("tc").wordCount
vc=tc.currentController.viewCursor
vc.gotoStart(false)
vc.goDown(5,true)
t.Add(tc.currentSelection, "cs1")
vc.goDown(2,false)
vc.goDown(5,true)
t.Add(tc.currentSelection, "cs2")
msgbox(test("cs1").getByIndex(0).string)
msgbox(test("cs2").getByIndex(0).string)
' scan collection, two methods
For i = 1 To t.Count
' o=test(i)
Next
s=""
For Each m In t
' m is value of current item, it's not the key of item
Next
t = nothing
It’s possible to obtain list keys as in javascript Object.keys(t) ?