in reply to variable reference problem

Your buffer is declared inside the loop, so the variable is cleared after every loop pass, so I find it hard to believe is has *any* value later.