Jump to content

code conflict affecting variable?


narrator
 Share

Recommended Posts

Hi,On my page, it first obtains the current folder name for use as a variable:<%Dim fs,fo,catSet fs=Server.CreateObject("Scripting.FileSystemObject")Set fo=fs.GetFolder(server.MapPath("."))cat=fo.nameset fo=nothingset fs=nothing%>It then correctly uses the "cat" (category) variable at the top of the page within a heading.A little lower, another routine chooses between FileExist else read in another file:<%Set fs=Server.CreateObject("Scripting.FileSystemObject")If (fs.FileExists(Server.MapPath("topleft.inc")))=true ThenSet f=fs.OpenTextFile(Server.MapPath("topleft.inc"), 1)Response.Write(f.ReadAll)f.CloseElseSet f=fs.OpenTextFile(Server.MapPath("../inc/topleft.inc"), 1)Response.Write(f.ReadAll)f.CloseEnd IfSet f=Nothingset fs=nothing%>Both alternate "topleft.inc" files make use of the "cat" variable as a heading. "<%=cat%>" but when it reads either file into the page, it prints that code instead of the variable. I can't work out why.Can someone advise why the above choose code is knocking out this variable?Any thoughts how to resolve it?Thanks :)

Link to comment
Share on other sites

deleted my reply.. thought i figured it out but hadn't..ran into "include" precedence.. sigh2nd edit:Thinking it through.. is it because at that point it is already executing the asp code and can't read in the cat code and execute it at the same time?

Edited by narrator
Link to comment
Share on other sites

Opening a file and printing the text is not the same as executing the code. You can use a regular include to include the file and have the code in it executed.http://www.w3schools.com/asp/asp_incfiles.asp
Thanks just.. as I said, I ran into include precedence. if existinclude file containing scriptelseend ifFortunately the top part of the include contained the script, so I just pulled that out and set it into the default file so it executes separate to include. I can see how precedence can do your head in.. lol.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...