Maybe it has something to do with the $line variable. Stick this in your code and see what it tells you. Maybe its a Val() issue.

? "Line=" + $line + " " + vartypename($line)
$line = CInt($line)
? "Line=" + $line + " " + vartypename($line)