In GLBasic you can use the SWAP command to swap values. You could then just use - SWAP drawlist[j],drawlist[j+1] and ignore the Val=bit completely.
You are also using "OR" 900 times every time you run this section of code - you'd be better separating them as the code reads "IF this OR that OR the other." It has to execute the whole line, whereas a standalone "IF" line terminates immediately if the IF is false. Or use CASE - pretty much of a muchness though.