Affected
The macro limit must exist and will be pre-compiled (regardless of whether it is in front)
There are often such requirements, requiring the number of different files such as the individual people according to different requirements, so it is required to dynamically include files.
code show as below:
Function include (filename) Dim re, content, fso, f, aspStart, aspEnd set fso = CreateObject ( "Scripting.FileSystemObject") set f = fso.OpenTextFile (server.mappath (filename)) content = f.ReadAll f.close Set f = nothing set fso = nothing set re = new regexp re.pattern = "^ / s * =" aspend = 1 aspstart = INSTR (Aspend, Content, "<%") 2 do while ASPSTART> Aspend 1 Response .write MID (Content, Aspend, Aspend-2) Aspend = INSTR (ASPSTART, Content, "% />") 2 Execute (Re.Replace (Content, AsPstart, Aspend-AspStart-2), " Respstart = INSTR (Aspend, Content, "<%") 2 loop response.write mid (content, aspend) set re = nothingend function
Use example:
Include ("Youinc.asp")
*********************************************************** ************
Can you dynamically include files? What is dynamic incrude?
answer
We talked from a case: <% 'Get the province's province DIM Province province = request.form ("province")' below shows the province's relevant information%> "-> Do you think the above code can work? Do not! Simply use ASP to achieve dynamic, you can't reach the effect you want. why? Because: The include command is executed before the ASP code, so the above code does not follow the author's will, first get the province's province, then contain information about this province!
If you really need to be dynamic, you can do this: <% SELECT CASE Provincecase 1:%>
It should be said that this code can get the result you want. However, because your users may come from 33 provinces, do you include 33 files? In particular, SSINC.DLL does not know which containment you need (in fact, this time the province has no value), so she contains all the files! You can imagine, how big this time is this! Then, asp.dll will scan the ASP code in this file and then execute! So, whenever this time, you should consider other ideas, such as databases, or FileSystemObject. How to dynamically include file?