Oh, I see why.
You have to apply that to the memory lcoations as well (which should never read that high, but let's just worry about the symptom at the moment.
Easiest way to fix it is to use a temporary long variable, or even a single.
dim temp as single
temp = (CLng(rob(n).mem(refvelup)) ^ 2 + CLng(rob(n).mem(refveldx)) ^ 2) ^ 0.5) ' how fast is this robot moving compared to me?
if abs(temp) > 32000 then temp = sgn(temp) * 32000
rob(n).mem(refvelscalar) = temp
replaces the single line you gave at the start of the code.
Now if that[ overflows, I'll eat my hat ;)