Global Function & Sub

A

Arne Tiedemann

Hi All,

i'm new in this Forum and in programming ASP Pages.

My Invironment
- Win2003 Server IIS6 asp enabled

I'll use an functions.asp file to put global Vars Functions an Sub routine
in it. How can I include this File to other ASP Files to use this functions,
vars or sub?

Thanks
 
S

Scott M.

You are talking about ASP.NET pages and not Classic ASP pages, right?

If so, put your global functions and subs in the Global.aspx files (mark
them as shared) and they'll be callable from anywhere in your assembly.
 
A

Arne Tiedemann

Hi,

I am using .asp Pages and I will put my Functions and other Global
Preferences in an File. This File should be included in other Files.

It is not easy to find help about this reason :) I hope anybody can help me.

Thanks
 
S

Scott M.

This newsgroup is about ASP.NET, but all you need to do for Classic ASP is
create a file that ends with .asp (it can end with other extensions, but for
security reasons, .asp is the way to go). This file should contain only the
script fragments that contain your functions and constant settings that you
want globally available.

On any .asp page that you need to use these functions, just add:

<!-- #include file="relative path to file" -->

to the <HEAD> section of the page.
 
S

Scott M.

Your syntax is wrong:

<!--#include virtual="/monitorex/config/functions.asp" //-->

should be:

<!-- #include virtual="/monitorex/config/functions.asp" -->

and you should only be using "virtual" if the functions.asp file is in a
different virtual directory from the file that is including it. If not, use
#include file.

Next, the code that you place inside the actual include file must be
delineated by scipt markers <% and %>. Your include file code should be:

<%
Function WMIDateStringToDate(dtmDate)
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & _
Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate, _
13, 2))
End Function
%>
 
S

Scott M.

I am confused by your design.

From what you've shown me about your header.asp file, I see no benefit from
making it an include file. All you are doing is making the process slower
by having an include have a link to a css file and then to another include.
This is bad design.

Functions.asp looks like the file that you want to use as an include file,
not header.asp.

Here's what I would have:
======================================================
functions.asp
======================================================
<%
Server.Execute("/monitorex/config/config.asp")

Function WMIDateStringToDate(dtmDate)
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & _
Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate, 13, 2))
End Function

CONST Test = "Testing 1111 1 1 11"
%>

=====================================================
Standard .asp file
=====================================================
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- #include virtual="/monitorex/config/functions.asp" -->

<title>Monitoring MS Exchange Server</title>
<link href="/monitorex/style.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<p align="center"><font size="+2">Overview of Events</font> </p>
<hr><br>
<%
on error resume next
if Request.QueryString("query") = "true" then
Dim counter, strComputer, strEventID
counter = 0
strComputer = Request.Form("strComputerName")
strEventID = Request.Form("strEventID")
end if
%>
<p><%=test%></p>
</body>
</html>
 
A

Arne Tiedemann

Hi Scott,

Sorry, how do you make an single head for all sites?
I am gratefully for all tips, as said Iam new in asp.

Thanks for your help
 
S

Scott M.

You can certainly use include files to act as a common header across many
pages, but in your header.asp file, there was nothing in there that wouldn't
be in every .asp file anyway. In other words, there was nothing unique
about your header.asp file, so there was no reason to have your pages have
to go and look for the include contents. But, I believe you were having
problems was the fact that you had an include file calling another include
file, which is generally considered a "no no".

In addiion to my suggestions for your code in the last post, here is a more
generic suggestion for using header includes (please note that the main file
should ALWAYS contain the complete structure for a basic, well-formed HTML
document). Also, please note that a "header" is generally asp code, text or
graphics (or all) that will appear at the top of several pages, not repeated
META tags or CSS links:

Main File:
================================================
<HTML>
<HEAD>
<TITLE>Some Page Title</TITLE>
</HEAD>
<BODY>
<!-- #include file="filePath" -->


</BODY>
</HTML>
 
S

Scott M.

Sorry, don't speak German, but if you remove the NOSPAM from the following
email address, you can email me:

(e-mail address removed)


Arne Tiedemann said:
Hello Scott,

thanks for your help!

Can we converse on German or can we email direct?

I am to end

Scott M. said:
You can certainly use include files to act as a common header across many
pages, but in your header.asp file, there was nothing in there that wouldn't
be in every .asp file anyway. In other words, there was nothing unique
about your header.asp file, so there was no reason to have your pages have
to go and look for the include contents. But, I believe you were having
problems was the fact that you had an include file calling another include
file, which is generally considered a "no no".

In addiion to my suggestions for your code in the last post, here is a more
generic suggestion for using header includes (please note that the main file
should ALWAYS contain the complete structure for a basic, well-formed HTML
document). Also, please note that a "header" is generally asp code, text or
graphics (or all) that will appear at the top of several pages, not repeated
META tags or CSS links:

Main File:
================================================
<HTML>
<HEAD>
<TITLE>Some Page Title</TITLE>
</HEAD>
<BODY>
<!-- #include file="filePath" -->


</BODY>
</HTML>



Hi Scott,

Sorry, how do you make an single head for all sites?
I am gratefully for all tips, as said Iam new in asp.

Thanks for your help

:

I am confused by your design.

From what you've shown me about your header.asp file, I see no
benefit
from
making it an include file. All you are doing is making the process slower
by having an include have a link to a css file and then to another include.
This is bad design.

Functions.asp looks like the file that you want to use as an include file,
not header.asp.

Here's what I would have:
======================================================
functions.asp
======================================================
<%
Server.Execute("/monitorex/config/config.asp")

Function WMIDateStringToDate(dtmDate)
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & _
Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate, 13, 2))
End Function

CONST Test = "Testing 1111 1 1 11"
%>

=====================================================
Standard .asp file
=====================================================
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- #include virtual="/monitorex/config/functions.asp" -->

<title>Monitoring MS Exchange Server</title>
<link href="/monitorex/style.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<p align="center"><font size="+2">Overview of Events</font> </p>
<hr><br>
<%
on error resume next
if Request.QueryString("query") = "true" then
Dim counter, strComputer, strEventID
counter = 0
strComputer = Request.Form("strComputerName")
strEventID = Request.Form("strEventID")
end if
%>
<p><%=test%></p>
</body>
</html>







Hello Scott,

so, now it works directly in the header.asp file but not in other files
:-(

I have an header.asp file that is the master Header File in this
file
I
will
include my functions.asp. In all other files I will only include the
header
file to get my header and get my Global functions and vars.

Here my Files (header.asp)
=====================================================
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Server.Execute("/monitorex/config/config.asp")
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- #include virtual="/monitorex/config/functions.asp" -->

<title>Monitoring MS Exchange Server</title>
<link href="/monitorex/style.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

=====================================================
other file
=====================================================
<!-- #include virtual="/monitorex/config/header.asp" -->

<p align="center"><font size="+2">Overview of Events</font> </p>
<hr><br>
<%
on error resume next
if Request.QueryString("query") = "true" then
Dim counter
Dim strComputer
Dim strEventID

counter = 0

strComputer = Request.Form("strComputerName")
strEventID = Request.Form("strEventID")
%>
<p><%=test%></p>
======================================================
complete functions.asp
======================================================
<%
Function WMIDateStringToDate(dtmDate)
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & _
Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate, _
13, 2))
End Function

CONST Test = "Testing 1111 1 1 11"
%>
======================================================


What is wrong? I am at the end






:

Your syntax is wrong:

<!--#include virtual="/monitorex/config/functions.asp" //-->

should be:

<!-- #include virtual="/monitorex/config/functions.asp" -->

and you should only be using "virtual" if the functions.asp file
is
in a
different virtual directory from the file that is including it.
If
not,
use
#include file.

Next, the code that you place inside the actual include file must be
delineated by scipt markers <% and %>. Your include file code should
be:

<%
Function WMIDateStringToDate(dtmDate)
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & _
Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate, _
13, 2))
End Function
%>



message
Hi Scott,

sorry, I dont find a MS Newsgroup fpr ASP only!

Your Answer dosnt work, I have included this file see below:
--------------------------------------------------------------------------
-----------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Server.Execute("/monitorex/config/config.asp") %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--#include virtual="/monitorex/config/functions.asp" //-->
--------------------------------------------------------------------------
-----------------------

in this file i put one function see below:
--------------------------------------------------------------------------
-----------------------
Function WMIDateStringToDate(dtmDate)
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & _
Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate, _
13, 2))
End Function
-------------------------------------------------------------------------- use
the
server.execute command to include an config file, in this file
i
use
application("Var"). This Variables work fine. I will also
migrate
this
Apllication("var") to the functions.asp file to use this vars.

I dont know
Thanks

:

This newsgroup is about ASP.NET, but all you need to do for Classic
ASP
is
create a file that ends with .asp (it can end with other extensions,
but
for
security reasons, .asp is the way to go). This file should contain
only
the
script fragments that contain your functions and constant settings
that
you
want globally available.

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top