开发者

VBScript Execute Method Does Not Declare Variables

I was looking into dy开发者_开发问答namic "includes" methods and came down to a solution which uses VBScript's Execute function. This works perfectly for me but I noticed that Execute executes the code but this code cannot declare anything like a variable or function:

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

Why? Thank you!


Perhaps you want to use ExecuteGlobal instead. I imagine that your dynamic includes file loader is in a subroutine, so when you use Execute, the new variables are scoped within that subroutine. ExecuteGlobal will ensure that the new variables are available globally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜