【问题标题】:VBScript Execute Method Does Not Declare VariablesVBScript 执行方法不声明变量
【发布时间】:2011-08-19 14:29:39
【问题描述】:

我正在研究动态的“包含”方法,最终找到了一个使用 VBScript 的 Execute 函数的解决方案。这对我来说非常有效,但我注意到 Execute 执行代码,但此代码不能声明变量或函数之类的东西:

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

为什么?谢谢!

【问题讨论】:

    标签: vbscript asp-classic execute


    【解决方案1】:

    也许您想改用ExecuteGlobal。我想您的动态包含文件加载器位于子例程中,因此当您使用Execute 时,新变量的范围在该子例程中。 ExecuteGlobal 将确保新变量在全局范围内可用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多