I have read elsewhere on this forum that IanM should have made a plugin that can sort string in alphabetic order, my own code is not working correct :-( It should sort the strings depending on the first letter, then in sorted groups depending on the first and the second letter.
sync on
sync rate 60
dim sorted_users(10)
dim user$(255)
user$(1) = "stefan"
user$(2) = "23"
user$(3) = "22"
user$(4) = "21"
user$(5) = "11"
user$(6) = "05"
user$(7) = "4"
user$(8) = "221"
user$(9) = "dummy string"
for user = 1 to 9
print user$(user)
next user
sync
wait key
group = 1
letter_to_check = 1
True=1: False=0
Repeat
SwappedString = False
For N=1 To 8
rem str1prep1$ = left$(user$(N),10)
str1prep2$ = mid$(user$(N),letter_to_check)
str1$ = lower$(str1prep2$)
Str1 = ASC(str1$)
rem str2prep1$ = left$(user$(N+1),10)
str2prep2$ = mid$(user$(N+1),letter_to_check)
str2$ = lower$(str2prep2$)
Str2 = ASC(str2$)
If Str1 > Str2
Temp$ = user$(N)
user$(N) = user$(N+1)
user$(N+1) = Temp$
SwappedString = True
Endif
Next N
Until SwappedString = False
`define groups of letters/numbers (i.e define "a","b","c" as groups)
For N=1 To 8
rem str1prep1$ = left$(user$(N),10)
rem str1prep2$ = mid$(str1prep1$,letter_to_check)
str1prep2$ = mid$(user$(N),letter_to_check)
str1$ = lower$(str1prep2$)
Str1 = ASC(str1$)
rem str2prep1$ = left$(user$(N+1),10)
rem str2prep2$ = mid$(str2prep1$,letter_to_check)
str2prep2$ = mid$(user$(N+1),letter_to_check)
str2$ = lower$(str2prep2$)
Str2 = ASC(str2$)
If str1 < str2
sorted_users(group) = N
group = group + 1
endif
next N
start_of_next_group = 1
group_end = sorted_users(1)
sort_another_group:
start_of_group = start_of_next_group
if sorted_users(group_end) - start_of_group > 0
Repeat
SwappedString = False
For N = start_of_group To sorted_users(group_end)
str1prep1$ = left$(user$(N),10)
str1prep2$ = mid$(str1prep1$,letter_to_check+1)
str1$ = lower$(str1prep2$)
Str1 = ASC(str1$)
str2prep1$ = left$(user$(N+1),10)
str2prep2$ = mid$(str2prep1$,letter_to_check+1)
str2$ = lower$(str2prep2$)
Str2 = ASC(str2$)
If Str1 > Str2
Temp$ = user$(N)
user$(N) = user$(N+1)
user$(N+1) = Temp$
SwappedString = True
start_of_next_group = N + 1
Endif
Next N
Until SwappedString = False
endif
group_end = group_end + 1
if group_end < group then goto sort_another_group
for user = 1 to 9
print user$(user)
next user
sync
wait key
The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...