Guidance
指路人
g.yi.org
software / rapidq / examples / GUI / Grid / QStringGrid Sort.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
     DECLARE FUNCTION SortColGrid (Sender AS QSTRINGGRID, Col% AS INTEGER, Ascend% AS INTEGER) AS STRING

' ******************************************************************
' FUNCTION TO QUICK SORT A ROWS BY SPECIFIC COLUMN IN THE GRIDSTRING
' Good sorts the text contents of cells, not for numbers (1,10,2,20)
' Example of Usage: SortColGrid (grd1, 3, 1)
' where grd1 = grid's name, 3 = sorted column, 1 = ascended sorting)
' By OvalX (iss@post.sk), 2.november 2002 (Update 24. november 2003)
' ******************************************************************

     FUNCTION SortColGrid
      $ESCAPECHARS ON
' Declaration variables
      DIM RecordsCount AS INTEGER
      RecordsCount = Sender.RowCount - 1
      DIM SortingArray(1 TO RecordsCount) AS STRING
      DIM MemoryStream AS QMEMORYSTREAM
      DIM I AS INTEGER, J AS INTEGER
' Change sorting Col% and first column
      IF Col% > 1 THEN Sender.SwapCols (1, Col%)
' Transfer data from Sender to MemoryStream
      Sender.SaveToStream (MemoryStream, 1,1,RecordsCount)
      MemoryStream.Position = 0
' Transfer data from MemoryStream to SortingArray
      FOR J = 1 TO RecordsCount
       SortingArray(J) = MemoryStream.ReadLine & "\n"
      NEXT J
      MemoryStream.CLOSE
' Sorting
      IF Ascend% = 1 THEN
       QUICKSORT(SortingArray(1), SortingArray(RecordsCount), Ascend)
      ELSEIF Ascend% = 0 THEN
       QUICKSORT(SortingArray(1), SortingArray(RecordsCount), Descend)
      END IF
' Back Transfer sorted data from SortingArray to MemoryStream
      FOR J = 1 TO RecordsCount
       MemoryStream.WriteStr(SortingArray(J), LEN(SortingArray(J)))
      NEXT J
      MemoryStream.Position = 0
' Back Transfer data from MemoryStream to Sender
      Sender.LoadFromStream(MemoryStream, 1, 1, RecordsCount)
      MemoryStream.CLOSE
' Back Change first column and Col%
      IF Col% > 1 THEN Sender.SwapCols (1, Col%)
      $ESCAPECHARS OFF
     END FUNCTION
掌柜推荐
 
 
¥264.00 ·
 
 
¥810.00 ·
 
 
¥1,480.00 ·
 
 
¥1,370.00 ·
 
 
¥1,290.00 ·
 
 
¥397.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2009-07-25 17:30:04