Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't conditionally include server script files

Status
Not open for further replies.

mgreer

Programmer
Jan 9, 2001
45
0
0
US
I have 3 files. One is main.asp, the other two are .vbs files with runat=server. These two files both have the same routines with different content. For example:

Main.asp declares a variable "Variable1".
Script1.vbs -
<script language=&quot;VBScript runat=server>
Function SetVariableText()
Variable1 = &quot;Script1text&quot;
End Function
</script>


Script2.vbs -
<script language=&quot;VBScript&quot; runat=server>
Function SetVariableText()
Variable1 = &quot;Script2Text&quot;
End Function
</script>


Now, in main.asp I try this:

If a = b then
<!--#INCLUDE FILE=&quot;script1.vbs&quot;-->
else
<!--#INCLUDE FILE=&quot;script2.vbs&quot;-->
end if

Even if a=b, Variable1 always equals &quot;Script2Text&quot;.

I realize that Server.execute would remedy this but unfortunately there are other routines in the script file that main.asp will need later so Server.execute is out of the question for me. I assume this is happening because the script runs on the server and it is being executed instead of just loaded hence the last variable to be set is what i see. Does anyone know a way around this, or know where to find documentation on this?

thanks.


 
All include files are loaded into asp files before any ASP code is executed. Therefore, you cannot use that method to select which include files you want to load based on an ASP conditional statement.

I believe that this topic has been discussed many times. You should search here to find more about this.
 
Obviously, your issue is more complicated than this, but...
Code:
select case a
  case b
    Variable1 = &quot;ServerVar#1&quot;
  case else
    Variable1 = &quot;ServerVar#2&quot;
end select
Gives you the same results..

Currently, you're overloading the SetVariableText() function... and the second one encountered always overwrites the first.

If possible, just set the necessary variables (content) conditionally, then run a single function.
 
Unfortunately it is more complicated than this. I wish I could put it all in one routine but that's not an option. I think I've found a workaround though. I'll post what I did after I iron out all the details.

thanks for your input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top