3

I was looking into dynamic "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!

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.