473,606 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

variable asp include

is there a way of having a file that's name is a variable (eg
dependant on the user name) act like a include.
i know that you cant define the file for an include asp tag using a
variable and that reading the file using "Response.W rite
FSO.OpenTextFil e(ppp, 1, False, False).readall" prints the file, and
treating it like a html file. can anyone suggest another way of doing
this?

Oct 15 '07 #1
6 4181
http://www.devguru.com/Technologies/...r_execute.html

<j.********@fin d-a-part.comwrote in message news:11******** *************@k 35g2000prh.goog legroups.com...
is there a way of having a file that's name is a variable (eg
dependant on the user name) act like a include.
i know that you cant define the file for an include asp tag using a
variable and that reading the file using "Response.W rite
FSO.OpenTextFil e(ppp, 1, False, False).readall" prints the file, and
treating it like a html file. can anyone suggest another way of doing
this?

Oct 15 '07 #2
j.********@find-a-part.com wrote:
is there a way of having a file that's name is a variable (eg
dependant on the user name) act like a include.
i know that you cant define the file for an include asp tag using a
variable and that reading the file using "Response.W rite
FSO.OpenTextFil e(ppp, 1, False, False).readall" prints the file, and
treating it like a html file. can anyone suggest another way of doing
this?
http://www.aspfaq.com/show.asp?id=2042
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Oct 15 '07 #3
Oops, didn't include a variable call to the function. Try this:

<html>
<body>
<p>Blah blah</p>
<%
sMyVar = Request.Queryst ring("var")

Select Case sMyVar
Case "1"
sMyFile = "file1.asp"
Case "2"
sMyFile = "file2.asp"
Case Else
sMyFile = "file.asp"
End Select

ExecInclude sMyFile
%>

<p>more blah</p>
</body>
</html>
Oct 19 '07 #4
j.********@find-a-part.com wrote on Mon, 15 Oct 2007 09:18:18 -0700:
is there a way of having a file that's name is a variable (eg dependant
on the user name) act like a include.
i know that you cant define the file for an include asp tag using a
variable and that reading the file using "Response.W rite
FSO.OpenTextFil e(ppp, 1, False, False).readall" prints the file, and
treating it like a html file. can anyone suggest another way of doing
this?
While Server.Execute is fine if the code in the "include" file is
self-contained, it won't work if you need to reference variables from the
"parent" code. You could pass all variables from the "parent" to the
"include" via the Session object, but with a large number of variables this
is impractical. Try Server.Execute and see if it'll fit your requirements,
if not then read on.

I had to do something similar recently and kludged a function together which
works so far with all the "include" files I've thrown at it - all my
"includes" are mixed ASP and HTML, and use variables from the "parent" page,
so Server.Execute and Server.Transfer were not suitable. My code isn't
pretty, and it's probably not very efficient either, but it works for me.
What this does is takes a filename, reads the file into a variable, and then
takes any inlined HTML and wraps it in Response.Write calls. It then
executes the resulting string which is now all ASP using the Execute call.
If the function returns False then the "include" file is empty or could not
be found. There's no error checking in the function, so you'll have to add
this yourself once you're happy it works.

To use the function, just do something like this:

<html>
<body>
<p>Blah blah</p>
<%
ExecInclude "myfile.asp "
%>
<p>more blah</p>
</body>
</html>

Here's the function:

Function ExecInclude(sFi le)
dim mfo, mf, sTemp, arTemp, arTemp2, lTemp, sTemp2, lTemp2, sFile2

If InStr(1,sFile," :") = 0 Then
sFile = Server.MapPath( sFile)
End If

'first read the file into a variable use FSO
set mfo = Server.CreateOb ject("Scripting .FileSystemObje ct")

'does file exist?
If mfo.FileExists( sFile) Then
'read it
set mf = mfo.OpenTextFil e(sFile, 1, false, -2)
sTemp = mf.ReadAll
mf.close
set mfo = nothing
Else
sTemp = ""
End If

If sTemp <"" Then
'sTemp contains the mixed ASP and HTML, so the next task is to
dynamically replace the inline HTML with response.write statements

arTemp = Split(sTemp,"<" & "%")
sTemp = ""

For lTemp = LBound(arTemp) to UBound(arTemp)

If InStr(1,arTemp( lTemp),"%" & ">") 0 Then
'inline asp
arTemp2 = Split(arTemp(lT emp),"%" & ">")

'everything up to the % is ASP code

sTemp2 = trim(arTemp2(0) )

If Left(sTemp2,1) = "=" Then
'need to replace with response.write
sTemp2 = "Response.W rite " & mid(sTemp2,2)
End If

sTemp = sTemp & sTemp2 & vbCrLf

'everything after the % is HTML
sTemp2 = arTemp2(1)

Else
'inline html only
sTemp2 = arTemp(lTemp)

End If

arTemp2 = Split(sTemp2,vb CrLf)
For lTemp2 = LBound(arTemp2) to UBound(arTemp2)
sTemp2 = Replace(arTemp2 (lTemp2),""""," """"") 'replace
quotes with doubled quotes
sTemp2 = "Response.W rite """ & sTemp2 & """" 'add
response.write and quoting

If lTemp2 < Ubound(arTemp2) Then
sTemp2 = sTemp2 & " & vbCrLf" 'add cr+lf if not the
last line inlined
End If

sTemp = sTemp & sTemp2 & vbCrLf 'add to running variable
Next

Next

Execute sTemp

ExecInclude = True

End If

end Function

Use this code at your own risk. It shouldn't cause any problems, but I can't
guarantee it. If anyone can suggest improvements to this I'd be happy to
hear them.

--
Dan
Oct 19 '07 #5
Daniel Crichton wrote:
>
Execute sTemp

Use this code at your own risk. It shouldn't cause any problems, but
I can't guarantee it. If anyone can suggest improvements to this I'd
be happy to hear them.
The basic problem with this is the use of Execute. For an explanation of why
I say this google Lippert and "Eval is Evil"

Many times, application development comes down to a choice between runtime
performance/efficientcy/resource-expenditure and developer convenience. I
typically choose the former.

I have faced this situation (needing to decide at runtime which include
files to load) but up to this point, I have been able to use encapsulation
techniques to avoid using Execute. However, at some point, a choice will
need to be made between the memory/cpu consumed by loading all the
encapsulated functionality
and the resources consumed by using Execute to avoid loading the entire
shebang. My intent in making this post is to make sure readers know that
this choice should be an intelligent one based on testing and measurements,
rather than just doing the one that makes writing the code a little easier.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Oct 19 '07 #6
Bob wrote on Fri, 19 Oct 2007 07:59:12 -0400:
My
intent in making this post is to make sure readers know that this
choice should be an intelligent one based on testing and measurements,
rather than just doing the one that makes writing the code a little
easier.
Oh, I agree. Sometimes it's just not possible to rewrite everything,
especially if the customer wants it finished yesterday. I always try to
avoid this sort of thing, and only use includes for common functions if
possible, but for one particular case this was the only solution I could
come up with in the specified timeframe and so far it's worked flawlessly,
and there's been no noticeable performance degradation (my use of it is on
an intranet system with a small number of users and a low transaction rate,
not a public web site).

--
Dan
Oct 19 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
15001
by: mark | last post by:
IF I have something like this: <title><?php print($pagetitle); ?></title> <body> <?php include("folders/my_include.php"); ?> </body> </html> and my_include.php contains the value to the variable ($pagetitle). How do I get the value before the code for the <title> is written. This is just a
2
2685
by: John Aspinall | last post by:
Hi, Ive got a navigation bar for my web pages in an include (top_nav.asp). On my homepage (index.asp) and all the other site pages I have a reference to this include which includes my navigation bar in each page. <!--#include virtual="/includes/nav/top_nav.asp"-->
2
1467
by: mark | last post by:
How does one call a variable defined in a class defined in file1.cpp from another file file2.cpp. Or can one call a class from a different file ? (Besides the standard way to define the variable in a header file and include this header file where required)
3
7644
by: Mike | last post by:
I'm new to PHP - moving over from ASP. I have a number of include files, the first of which sets the value of a variable $loginmsg. I use that variable in a subsequent include file, but get a "Notice: Undefined variable loginmsg" warning. I've had a good look at previous posts concerning this warning, and see that isset() is recommended to prevent this kind of warning. Is this totally necessary? In ASP, and include file becomes...
8
3503
by: chellappa | last post by:
hi Everybody ! decalaring variable in a.h and using that vaaariable in a1.c and inalization is in main.c it is possible .........pleaase correct that error is it Possible? i am trying it gives error! In file included from main.c:2: a1.c:3: error: initializer element is not constant
13
1841
by: GGawaran | last post by:
First off, Hi everyone new to .asp and am trying to self teach myself. Im trying to figure out what exactly im doing wrong, or maybe what I think I can do, I really cant. The Idea. ------------------- On our website, we have several pieces of code we entered in so in the event that when you click on the category section, and "Engraving" was selected, it would load an include file and show our engraving options, etc. Well, I figured, we...
13
2009
by: Justcallmedrago | last post by:
How would you declare and assign a variable inside a function THAT HAS THE NAME OF A PARAMETER YOU PASSED example: when you call createvariable("myvariable") it will declare the variable "myvariable" and then maybe assign it something. myvariable = "this is a real variable"
3
1829
by: leonardodiserpierodavinci | last post by:
Hi. Sorry for what is perhaps a neophyte question: is it possible to pass a variable to a PHP script from inside another PHP piece of code? For instance, the file test.php (which of course resides on a webserver that supports PHP) is as such: <?php echo("<i>the variable abc contains " . $_GET . "</i>"); ?>
7
1692
by: atwiawomo | last post by:
Hi This may be simple to solve, but I can't seem to do it :( I am trying to generate an include name on an image gallery page from a variable name. By this I mean I already have a numeric value set the variable $imageCat. What I want to do is pull in an external include file using the
0
8024
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7959
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8310
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5968
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3942
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3987
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1305
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.