Reusable Code

Results 1 to 4 of 4

Thread: Reusable Code

  1. #1
    Join Date
    Dec 1969

    Default Reusable Code

    Can I store a bunch of functions in one page, and refrence them from all my other pages so I don&#039t cluter all my pages up with the same code. <BR>Any help would be appreciated.<BR><BR>Thanks,<BR><BR>Mike

  2. #2
    Mark Guest

    Default RE: Reusable Code

    Store all your Functions in an Include File (e.g funstions.asp), then include this file in all your asp pages.<BR><BR>e.g.<BR>&#060;%@ LANGUAGE="VBScript" %&#062;<BR>&#060;!--#include file=""--&#062;<BR>&#060;!--#include file="functions.asp"--&#062;<BR>&#060;!--#include file=""--&#062;<BR>&#060;!--#include file=""--&#062;<BR>.<BR>.<BR>.<BR> Include files can be suffixed with anything. Usually *.inc or *.asp are used. For better security, I prefer to identify all Include files with *.asp suffixes.

  3. #3
    KPW Guest

    Default RE: Reusable Code

    Absolutely. This is just the type of thing Server Side Includes were made for.<BR><BR>To reference an include file from one of your pages, you must give it an extension such as .asp or .shtml or something that your server recognizes as needing to go through a special parser. It&#039s most likely that you&#039ll want to use the .asp extension.<BR><BR>Next, in your ASP page, you need a line like the following:<BR><BR>&#060;!--#include [file/virtual]="[path to file]"--&#062;<BR><BR>If you use "file" then "[path to file]" needs to be a relative path from the file in which the ASP page is located. If you use "virtual" then "[path to file]" needs to be a virtual path from the web server&#039s root.<BR><BR>For example:<BR><BR>&#060;!--#include file="functions.asp"--&#062;<BR><BR>or<BR><BR>&#060;!--#include virutal="/includes/functions.asp"--&#062;<BR><BR>As an extra measure of security, you should name your include files .asp rather than .inc. If you name your file .inc then anyone could type in the path to your include file and view the code for your functions!<BR><BR>I hope this helps. If you have any trouble, just post another message.<BR><BR>KPW

  4. #4
    Rob Guest

    Default RE: Reusable Code

    Mike...<BR>Just to add to the melee here. I use a common folder where I keep alot of stuff including a Main.js where I keep Javascript functions and Main.vbs where I keep vbscript subs and functions. I also have Local.js and Local.vbs files for functions that are not global or just pertinant to a particular folder.<BR>Hope this doesn&#039t confuse you.<BR><BR>Regards,<BR>Rob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts