2011-08-19 60 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將確保新變量在全球範圍內可用。