Here's the cleaned up code. I've tried it in a nearly empty program witn only the code required to use the function. It still says "type mismatch".