How to pass a variable to a function?

I'm guessing it is a scope issue, but that's just from my limited view of your code.