DEFINT A-Z DECLARE SUB SORT (A$()) DECLARE FUNCTION STRCMP (A$, B$) DECLARE FUNCTION GETCHAR (S$, PTR) ' Sorts an array of strings using the bubble sort algorithm. SUB SORT (A$()) L = UBOUND(A$) FOR I = L TO LBOUND(A$) STEP -1 FOR J = L TO I STEP -1 IF STRCMP(A$(I), A$(J)) > 0 THEN SWAP A$(I), A$(J) NEXT J NEXT I END SUB ' Compares string A to string B. (not case sensitive) ' Return value = 0 if A = B ' Return value > 0 if A > B ' Return value < 0 if A < B FUNCTION STRCMP (A$, B$) AA$ = UCASE$(A$) BB$ = UCASE$(B$) IF AA$ = BB$ THEN STRCMP = 0: EXIT FUNCTION FOR K = 1 TO LEN(A$) + 1 CA = GETCHAR(AA$, K) CB = GETCHAR(BB$, K) IF CA < 0 AND CB >= 0 THEN STRCMP = -1: EXIT FUNCTION IF CB < 0 AND CA >= 0 THEN STRCMP = 1: EXIT FUNCTION DIFF = CA - CB IF DIFF THEN EXIT FOR NEXT K STRCMP = DIFF END FUNCTION ' This function grabs one byte from string S and returns its ASCII ' character code. When PTR is negative, it grabs a character from ' the end of string. When PTR is out of range, -1 is returned. ' Example : GETCHAR("ABCD", 1) -> 65 = "A" ' GETCHAR("ABCD", -2) -> 67 = "C" ' GETCHAR("ABCD", 23) -> -1 (out of range) ' GETCHAR("ABCD", 0) -> -1 FUNCTION GETCHAR (S$, PTR) P = PTR LS = LEN(S$) IF P < 0 THEN P = P + LS + 1 IF LS = 0 OR P < 1 OR P > LS THEN GETCHAR = -1: EXIT FUNCTION GETCHAR = ASC(MID$(S$, P, 1)) END FUNCTION