You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
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.
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
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
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: