can you explain what you are trying to achieve ?
do you in fact have multiple buttons each with a different R4 ?
did you try my second example ? is it even relevant if not what needs to happen differently ?

at this stage I still can't see how an array sorting routine is in any way useful for detecting button presses long or short .
why not post the code for what have you tried

dt_elapsed will not run on a12f675