Search code examples
vbscriptasp-classic

ASP Option Explicit - Paypal Express Checkout trouble


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?


Solution

  • 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".