[Gambas-user] Array.Sort

Lewis Balentine lewis at ...3412...
Wed Jan 7 23:55:26 CET 2015


I was playing around trying to learn how to pass string arrays back and 
forth.
I then looked at the array.sort function. The prototype in the Wiki 
indicates that it returns an "string[]".

       Function Sort([Mode As Integer]) As String[]

However it seems that I can not use the returned values(s) where I would 
normally use an array. It appears to to me to operate more as a SUB than 
a FUNCTION in that it resorts the array but does not return something 
that I can use in another function or procedure. Is my interpretation of 
the prototype wrong-headed ?

Regards,

Lewis Balentine

'================================================
Private Function TestFunction() As String[]
   Return ["TEST:abcdefghij", "TEST:1234567890", "TEST:ABCDEFGHIJ"]
End

Private Sub DoPrint(XXX As String[])
   Dim S As String
   For Each S In XXX
     Print S
   Next
   Print "------"
End


Public Sub Main()
   ' From Gambas Wiki:
  '     Function Sort([Mode As Integer]) As String[]
  '     Sort the array.
  '
   Dim XXX As String[] = ["XXX:abcdefghij", "XXX:1234567890", 
"XXX:ABCDEFGHIJ"]
   Dim S As String

   ' All of the following work as expected
   DoPrint(XXX)
   DoPrint(TestFunction())
   XXX.Sort
   DoPrint(XXX)
   XXX = TestFunction()
   XXX.Sort
   DoPrint(XXX)

   ' None of the following works: Type Mismatch, wanted string[] got 
function instead
   ' xxx = TestFunction().sort
   ' DoPrint(XXX.sort)
   ' DoPrint(TestFunction().sort)

   ' For Each S In XXX.Sort                '  not an object
   '   Print S
   ' Next
   ' Print "-------"

   ' For Each S In TestFunction().sort       '  not an object
   '   Print S
   ' Next

   Quit
End

' [System]
' Gambas = 3.6.2
' OperatingSystem = Linux
' Kernel = 3.13.0 - 24 - generic
' Architecture = x86_64
' Distribution = Linux Mint 17 Qiana
' Desktop = MATE
' Theme = QGtk
' Language = en_US.UTF - 8
' Memory = 15994 M
' [Libraries]
' Cairo = libcairo.so.2.11301.0
' Curl = libcurl.so.4.3.0
' DBus = libdbus - 1. so.3.7.6
' GStreamer = libgstreamer - 0.10.so.0.30.0
' GStreamer = libgstreamer - 1.0.so.0.204.0
' GTK + 3 = libgtk - 3. so.0.1000.8
' GTK += libgtk - x11 - 2.0.so.0.2400.23
' OpenGL = libGL.so.1.2.0
' Poppler = libpoppler.so.44.0.0
' Qt4 = libQtCore.so.4.8.6
' SDL = libSDL - 1.2.so.0.11.4




More information about the User mailing list