Hi Primo,
sorting by specified UDT member would be great - and I think the syntax could be even simpler than in PureBasic, because ThinBASIC is able to determine TypeOf the element.
Looking at your code, I think you could make your life more comfy by having routines to fill and print your data.
See this tweaked version:
Uses "console"
Dim i As Long
Type template
' -- Data
sName As Long
SValue As Word
sCount As Long
' -- Functions
' Fills in all the values at once!
function init(sName as long, sValue as word, sCount as long)
me.sName = sName
me.sValue = sValue
me.sCount = sCount
end function
' Represents type as string
function to_string() as string
return strformat$("{1}{2}{3}{4}{5}", me.sName, $TAB, me.sValue, $TAB, me.sCount)
end function
End Type
Dim symbol(10) As template
'sName, sValue, sCount
symbol(1).init( 22, 1, Rnd(1,1000))
symbol(2).init( 18, 2, Rnd(1,1000))
symbol(3).init( 2, 3, Rnd(1,1000))
symbol(4).init( 6, 4, Rnd(1,1000))
symbol(5).init( 9, 5, Rnd(1,1000))
symbol(6).init( 87, 6, Rnd(1,1000))
symbol(7).init( 54, 7, Rnd(1,1000))
symbol(8).init( 33, 8, Rnd(1,1000))
symbol(9).init( 4, 9, Rnd(1,1000))
symbol(10).init( 5, 10, Rnd(1,1000))
PrintL "============ before sorting"
For i = 1 To 10
PrintL symbol(i).to_string()
Next ' <- no need to specify variable with next
Array Sort symbol, DESCEND 'ASCEND
PrintL "============ after sorting"
For i = 1 To 10
PrintL symbol(i).to_string()
Next
printl
printl "end."
WaitKey (60)
Bookmarks