views:

421

answers:

1

Hi guys, I am facing a big trouble when integrating PayPal Express Checkout in classic ASP.

The code provided by PayPal at the "PayPal Integration Wizard" works perfectly when run without Option Explicit.

When I put into my coding pages and call to the functions provided, I am facing big trouble: My existing pages all use Option Explicit.

This results in me having to manually declare all variables in the PayPal functions.

The sample PayPal functions consist of many array/list/object/index for setting up the name/value pairs necessary to call the PayPal site. It is totally not easy for me to change it over to all correct declaration, since I am not ASP expert and project deadline is tight.

Can anyone give me some advice?

+3  A: 

It seems to be possible to mix "Option Explicit"-code with non-"Option Explicit"-code via the Execute statement.

Here's a small test I just made with VBScript (which applies to classic ASP as well):

''#vb1.vbs (i.e. "your code")
Option Explicit

Dim fso, vb2, txt
Set fso = CreateObject("Scripting.FileSystemObject")
Set vb2 = fso.OpenTextFile("vb2.vbs", 1)
txt = vb2.ReadAll

MsgBox txt    ''# Message 1
Execute txt

MsgBox foo    ''# Message 2

and

''# vb2.vbs (i.e. "their code")
j = 100

Function foo
  k = 100
  foo = j + k
End Function

Results in:

Message 1: (equal to the contents of vb2.vbs)
Message 2: 200

I have no idea if this is the best way to do it, but currently I can think of no better way. Give it a try.

Beware of namespace clashes through global variables or function names in "their code".

Tomalak
The downside is that ASP will cache parsed/tokenised and otherwise "compiled" ASP pages. Whereas any code passed to Execute needs to be parsed and "compiled" each time the page is called.
AnthonyWJones
The namespace collision risk can be mitigated by place most of your own code in a class thereby significantly reducing the set of identifiers you code creates at the global level.
AnthonyWJones
@AnthonyWJones: +1 for both of your comments, your're right. On the other hand - I think the parsing/compiling business takes negligible time, as it happens in-thread. The Script engine doing the request is already loaded, and the PayPal code will be trivial enough to be availibe within milliseconds. Nothing I would worry about.
Tomalak