Visual Basic
Web Scripting
Java
Click Here


Home

What's New

Articles

Code Downloads

Code Snippets

Message boards

Links
Tool Box

Books

Mailing List
Receive free code snippets and notices when this site is updated.

Contact

Active Server Page Code Snippets

Creating a Simple Page Counter *1

This code will create a very simple page counter.  It gets incremented every time the page is loaded and if the server is shutdown the count is lost.

<%
  ' Lock the application
  Application.Lock
  ' Get the name of the file name executed
  sFileName = Request.ServerVariables("SCRIPT_NAME")
  ' Increment the count for this file
  Application(sFileName) = Application(sFileName) + 1

  Response.write "<H1>" & Application(sFileName) & "</H1>"

  ' Unlock the application
  Application.Unlock

%>

Stripping HTML Tags from a String

If you need to prevent html code from be displayed(e.g. A Message board were added HTML could stuff up the layout) you can use this script to remove the html tags from a string.

<%
Function StripHTML(ByVal strHTML)
  Dim InsideTag
  Dim i

  Total = Len(strHTML)
  ' Scan if there is a tag, and determine if you should add it
  ' to the finished file.
  For i = 1 To Total
    Select Case Mid(strHTML, i, 1)
      Case "<"
        InsideTag = True
      Case ">"
        InsideTag = False
      Case Else
        ' If it is InsideTag then don't add it to the file, and
	' if it isn't, then add it to the previous ToFile text.
	If Not InsideTag Then StripHTML = StripHTML & Mid(strHTML, i, 1)
      End Select
  Next
End Function
%>

*1. This code sample was printed in "Build Simple Hit Counters in ASP" by Manohar Kamath, Microsoft Interactive Developer, August 1998, copyright Microsoft Corp. and is reprinted by permission. All rights reserved. For more information about MIND, please visit www.microsoft.com/mind.