Web Application Development Advice & How To
Active Server Pages Development Advice & How To

Shining Star Services LLC
 
Shining Star Services
Articles
ASP.NET
ASP.net Articles
ASP, DHTML, HTML
HTML Tutorial
Auto-select an Element from a Menu or Scrolling List & Save Keystrokes!
ASP Driven DHTML Slider Menus REVISITED One Year Later! Part II
ASP Driven DHTML Slider Menus
ASP Driven HTML Outlines
Reusing Code with ASP Include Files and Subroutines
Security
Hacker Query Check
.htr IIS Security Issue
Databases, Cookies
Functions to Open a Database Connection and Record Set
Setting Up and Using OraSession to Manage Your Oracle Database Objects
Storing Non-Durable Data for Cookie-less Sessions
Javascript
Smart Popups
Javascript: Validate Numeric Fields
Javascript Confirm Form Submission
Javascript Dynamic Text Area Counter
Javascript: Check All and Uncheck All Check Boxes
Javascript Field Validations -- Client Side Scripting
Miscellaneous
Tree Select Demo
Adobe Extension Manager
Scandisk & Defrag Pointers
Standards & Style
Setting Up Your Own ASP Development Templates
Creating a Project Template for Estimations of Time, Tasks, and Resources
To Host or Not To Host
ASP Naming Conventions
HTML Naming Conventions & Visual Interdev HTML Generation
Working with and in spite of the Visual Interdev Design Mode
Commenting Your ASP Source Code
Letters!
Reader Letters

Articles Home

Shining Star Services

 
Reusing Code with ASP Include Files and Subroutines
By Nannette Thacker - 05/01/1999

I call it "Frankenstein" code when an author cuts and pastes the same snippet of code over and over throughout an application. What a maintenance nightmare!!!

Later you may have to update 50 snippets of code and imagine what happens when you miss updating a few!

Reuse Code - Use Includes or Create Subroutines

Writing subroutines or using an include file is easy to do. Then later on, when updating is necessary, only one piece of code must be edited! You may have a function which converts a date string into something like this: "JAN-24-99." Place the code in a subroutine, in an include file, so that it can be called on each page that uses it:

This would be in the "include" file "DateToText.asp":

<%
   Function DateToText(convertdate)
      DateToText = ' remainder of code goes here
   End Function
%>

Call the DateToText function in the files which use it:

<!--#include virtual="/include/DateToText.asp"-->

I have edited a major application where the header, logo, and links on every page were identical, yet they were cut and pasted into every page! What a horror trying to ensure that changes were made consistently, and tested, on every single page!

If the developer had used forethought, this information would have been placed into an include file, which would be called at the top of every page. Thus, any changes would be made once, and testing only a few of the pages would have been ample.

(What if the header is "similar" on every page, but has a few differences? See my article on Using Templates With Your ASP Development for ideas.)

Include File Naming Conventions

Include files can be named with the "inc" extension. However, for two reasons, I prefer using the "asp" extension:

  1. Color-Coded: The "asp" extension allows color-coded editing within Visual Interdev. That alone is reason enough for me. You can easily spot problems while coding!
  2. Security Issues: Functions written in files using the "inc" extension can be opened in a browser window and viewed. Functions written in files using an "asp" extension are not displayed to the viewer, thus keeping the source code hidden from prying eyes.

I prefer keeping "include" files used throughout the entire project in an "include" subdirectory. But if an include file is unique to a given module, I prefer keeping the include file in that module's directory.



ChristianSinglesDating

ShiningStar.net | ShiningStarSingles.com | Christian911.com