Well, I'd start by adding in DEBUG code.
For starters, replace the line:
Execute ( Mid(str,1,a2-1))
(and any other Execute lines) with
Response.Write "<HR><h2>EXECUTE:</h2>" & Mid(str,1,a2-1) & "<HR>"
or similar. The idea being to dump out to the screen all those things that would be Execute'd, to find out just what he really is trying to do.
But I'll tell you now, if you aren't a pretty experienced ASP coder, this is going to take you some time to decipher and fix. If you dumped it in my lap--and I consider myself to be a really advanced ASP coder--I wouldn't even give you an estimate of time-to-fix until I'd been able to do some initial debugging, trying to figure out just what the code is doing.
I'd almost surely try to talk you into throwing out the code and starting over with at least this part of it. The *need* to use Execute in a page tells me there was probably a fundamental flaw in the initial design.
Are there exceptions? Of course. But they are so rare that they are unlikely to apply in this case. Again, without diagnosing what's going on now, I couldn't tell.