The problem here is that the events themselves are Subs (you can see this if you look at the header and footer in the script editor. VBScript (unlike JScript) doesn’t support nesting Subs or Functions.
There are two solutions to this, a recommended solution and a non-recommended solution.
Recommended Solution: Place the Function code in the Project Global Script (choose Project Global Script from the Project menu.)
Non-Recommended Solution: You can actually end the event inside the script editor by typing “End Sub”, then put in your function/sub after it. Remember that an extra End Sub will be placed on the end, so leave off the last End Sub or start a dummy Sub at the bottom. We don’t really recommend this, because it makes for fairly unreadable code - it’s not by design, it just happens to work. Let me know if you’d like a better explanation.
I guess the other solution would be to move to JScript, where functions can be nested.