2011-08-19 63 views
3

我正在研究动态的“包含”方法,并归结为使用VBScript的执行功能的解决方案。这完全适用于我,但我注意到,执行执行代码,但是这个代码不能像声明一个变量或函数的任何信息:VBScript执行方法不声明变量

Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 
If objFSO.FileExists(Server.MapPath(strFile)) Then 
    Set objFile = objFSO.OpenTextFile(Server.MapPath(strFile), 1) 
    strSource = objFile.ReadAll 

    // Filter out comment- and ASP tags cos they return errors 
    strSource = Replace(strSource, Chr(60)&Chr(37), "") 
    strSource = Replace(strSource, Chr(37)&Chr(62), "") 
    objRegExp.Pattern = "^[ \t]*(//¦\')[\s\S]*?$" 
    strSource = objRegExp.Replace(strSource, "") 

    // Execute the code 
    On Error Resume Next 
    Execute strSource 'etc........ 
end if 

为什么?谢谢!

回答

2

也许你想用ExecuteGlobal来代替。我想象你的动态包含文件加载器是在一个子程序中,所以当你使用Execute时,新变量在该子程序范围内。 ExecuteGlobal将确保新变量在全球范围内可用。