Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Sort Whole Or Part Of 2 Dim String Array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sort Whole Or Part Of 2 Dim String Array

    Code:
    FUNCTION Two_Dimension_String_ARRAY_SORT( AR( ) AS STRING, BYVAL Sort_ColNum AS LONG, BYVAL R_Start AS LONG, BYVAL R_End AS LONG, BYVAL C_Start AS LONG, BYVAL C_End AS LONG, BYVAL Row_Number_Location AS LONG, BYVAL ASCEND_DESCEND AS BYTE ) AS LONG
    	'
    	' Call Function With AR( ) To Sort
    	' Sort_ColNum : Column To Perform Sortation On
    	' R_Start : Row Starting Position In AR( )
    	' R_End   : Row Ending Position In AR( )
    	' C_Start : Column Starting Position In AR( )
    	' C_End   : Column Ending Position In AR( )
    	' Row_Number_Location : FUNCTION = New Position Of The Row Requested
    	' ASCEND_DESCEND : %Ascending or %Descending As Required
    	
    	LOCAL TL1 AS LONG
    	LOCAL TL2 AS LONG
    	'
    	DIM Copy_Array( R_Start TO R_End, C_Start TO C_End ) AS STRING
    	DIM Copy_Array_Sort( R_Start TO R_End ) AS STRING
    	DIM Copy_Array_Sort_Index( R_Start TO R_End ) AS LONG
    	'
    	FOR TL1 = R_Start TO R_End
    		Copy_Array_Sort_Index( TL1 ) = TL1
    		Copy_Array_Sort( TL1 ) = AR( TL1, Sort_ColNum )
    		FOR TL2 = C_Start TO C_End
    			Copy_Array( TL1, TL2 ) = AR( TL1, TL2 )
    		NEXT TL2
    	NEXT TL1
    	'
    	IF ASCEND_DESCEND = 1 THEN
    		ARRAY SORT Copy_Array_Sort( ), COLLATE UCASE, TAGARRAY Copy_Array_Sort_Index( ), DESCEND
    	ELSE
    		ARRAY SORT Copy_Array_Sort( ), COLLATE UCASE, TAGARRAY Copy_Array_Sort_Index( ), ASCEND
    	END IF
    	'
    	FOR TL1 = R_Start TO R_End
    		FOR TL2 = C_Start TO C_End
    			AR( TL1, TL2 ) = Copy_Array( Copy_Array_Sort_Index( TL1 ), TL2 )
    		NEXT TL2
    	NEXT TL1
    	'
    	ARRAY SCAN Copy_Array_Sort_Index( ), = Row_Number_Location, TO TL1
    	'
    	FUNCTION = TL1
    	'
    END FUNCTION

  • #2
    This function works on arrays with more than 2 columns

    Function Renamed

    Code:
    FUNCTION Multi_Dimension_String_ARRAY_SORT( AR( ) AS STRING, BYVAL Sort_ColNum AS LONG, BYVAL R_Start AS LONG, BYVAL R_End AS LONG, BYVAL C_Start AS LONG, BYVAL C_End AS LONG, BYVAL Row_Number_Location AS LONG, BYVAL ASCEND_DESCEND AS BYTE ) AS LONG

    Comment

    Working...
    X