Exactly as you say: there is a bug in your function -- but no bug in bwbasic...