I have an array of custom types that I want to sort.
I tried different sort routines that did not work and traced it down to the swap section of the sort.
Swapping items in the array does not work:
REM ***** BASIC *****
public type aType
num as integer
str as string
end type
public arr(3) as aType
public tmp as aType
Sub Main
arr(0).str = "aaa"
arr(0).num = 0
arr(1).str = "bbb"
arr(1).num = 1
arr(2).str = "ccc"
arr(2).num = 2
arr(3).str = "ddd"
arr(3).num = 3
tmp = arr(2)
arr(2) = arr(3)
arr(3) = tmp
dim inx as integer
dim str as string
str = ""
for inx = 0 to ubound(arr)
str = str & "arr(" & inx & " ).num = " & arr(inx).num & chr$(13)
next inx
msgbox str
End Sub
PLEASE tell me what I am doing wrong.
If there is a built-in sort routine that can be used, please let me know.
INFO:
Version: 7.5.3.2 (X86_64) / LibreOffice Community
Build ID: 9f56dff12ba03b9acd7730a5a481eea045e468f3
CPU threads: 12; OS: Windows 10.0 Build 22621; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL threaded