ASP
  Home arrow ASP arrow Page 6 - Writing Your First ASP Application ( Quick...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Writing Your First ASP Application ( Quick Start )
By: Rich Smith
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 82
    2003-08-06

    Table of Contents:
  • Writing Your First ASP Application ( Quick Start )
  • Users On Your Website
  • Dissecting The Needs For The Application
  • Login Page
  • Showing The List Of Users
  • Simplifying The Code
  • Removing Users From The List
  • Additional Enhancements

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Writing Your First ASP Application ( Quick Start ) - Simplifying The Code


    (Page 6 of 8 )

    The ASP page for showing the users is functional as shown in the previous section. But it can be pretty difficult to modify the look and feel of the page when you have a hearty mix of script and HTML. And what if you want to show the users on more than one page? Do you want to type the same code over and over again?

    One method of simplifying your ASP pages is to use include files and functions. Include files are other basically other files containing HTML and/or script that you can reference from your ASP page, and will be considered part of the ASP page when the page is rendered. In this method, you can put code that you want to use on more than one page in an include file, and reference the file from many ASP pages. Include files can also be used to hide complex code to make it easier to modify the design of the HTML on your web pages.

    Here is another copy of the showusers.asp page, this one using an include file with a function to show the users:

     <%@ LANGUAGE="VBSCRIPT" %><!-- #INCLUDE FILE='functions.inc' -->Users currently on the website: 
    <HR>
    <%
    ShowUsers
    %>

    And here is the functions.inc:

     <%

    Sub ShowUsers()

    dim conn
    dim strsql
    dim mycount

    ‘ Create a SQL statement to insert the name into our table
    strsql 
    "select UserName from UsersOnline”

    ‘ Open the database using our DSN
    strconn = “DSN=UserBase”

    set conn = server.createobject("
    adodb.connection")
    conn.open strconn

    ‘ Open the recordset containing user names
    Set rs = Server.CreateObject("
    ADODB.Recordset")
    rs.Open strsql, conn, 3,3

    ‘ Set the mycount variable to contain the number of users in the database
    mycount=rs.recordcount

    if mycount < 1 then
    ‘ There were no users logged in
    response.write “None”
    else
    for a = 1 to mycount
    ‘ Write out the user names
    response.write(rs(“UserName”))
    if a < mycount then
    rs.movenext
    end if 
    next a
    endif

    ‘ Close the recordset
    rs.close
    set rs = nothing

    ‘ Close the database connection

    conn.close
    set conn = nothing

    End Sub

    %>

    As you can see, all of the working code has been put inside the functions.inc file in a subroutine called “ShowUsers”. The ASP page has become very compact and easy to read and modify. In addition, the functions.inc file can be included on any ASP page in your application, and used to display the users wherever you would like.

    More ASP Articles
    More By Rich Smith


     

    ASP ARTICLES

    - Using MySQL with ASP
    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT