Thanks a lot Salem, actually that's the advice I was looking for, I was on the wrong track with pointers.
The most important thing is to find the correct way to solve a problem.
I followed your advice completely and made a function (only three lines) that refreshes the value when necessary. Now the complete code works great.