Categories

Subscribe via Email

Enter your email address to subscribe and receive notifications of new content by email.

Check A Date Is Valid

This example displays a form on a page . The user then enters a date , if the date is invalid then a message will be displayed on the screen . Examples of valid dates are as follows

12-12-09

12/12/09
<form method =”post” action=”<%= Request.ServerVariables(“SCRIPT_NAME”) %>”>
<input type =”text” name=”date”><br>
<input type=”submit”>
</form>
<%

Dim strDate , blnValid , dteDate
If Request.ServerVariables(“CONTENT_LENGTH”) <>0 Then
strDate = Trim(Request.Form(“date”))
‘check and see if the user entry is a date
If isDate(strDate) Then
dteDate = CDate(strDate)
‘set variable to true
blnValid = True
Else
‘display invalid date message
Response.Write “You entered an invalid date”
End If
‘displayvalid date message
If blnValid = True Then
Response.Write “The date you entered was ” & dteDate
End If
End If
%>

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBibSonomyDeliciousDiggDiigoSina WeiboWordPressBlogger PostShare

More accurate text counter

This is a more accurate counter than our previous example , in this example the count only gets incremented once per session . This means your count will be more accurate if you want it to be that is.

Create a txt file and put your starting number in it . Then copy the code snippet below where you want the counter to display on your page.

In the example below the counter.txt is placed in the same directory as this page , if you put the txt file elsewhere remember and alter the Server.MapPath part of the code.

Visitor number

<%
‘create a FileSystemObject
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
‘this is the path to our counter file
CounterFile = Server.MapPath(“counter.txt”)
Set objCount = objFSO.OpenTextFile(CounterFile)
visitorcount = CLng(objCount.ReadLine)
if Session(“visitorcount”) = “” then
Session(“visitorcount”) = visitorcount
visitorcount = visitorcount + 1
objCount.close
Set objCount = objFSO.CreateTextFile(“counter.txt”, True)
objCount.WriteLine(visitorcount)
end if
objCount.Close
‘display count
Response.Write visitorcount
%>

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBibSonomyDeliciousDiggDiigoSina WeiboWordPressBlogger PostShare

Create an XML file

In this example we are going to create a simple XML document on the web server . The structure of the document will be as follows .

<?xml version=”1.0″ ?>
<news>
<newsitem>
<title>programmingsite.co.ukP</title>
<link>http://www.programmingsite.co.uk</link>
<description>programming resources</description>
</newsitem>
</news>

Anyway lets go with the code to create this example

<%@LANGUAGE = “VBScript” %>
<%
Response.Buffer = False
‘ensure proper headers sent to the client
Response.ContentType = “text/xml”
%>
<?xml version=”1.0″?>
<%

‘these are our variables
Dim objXML , objNews
‘create an instance of the DOM
Set objXML = Server.CreateObject(“Microsoft.XMLDOM”)
‘Create our root element using the createElement method
Set objXML.documentElement = objXML.createElement(“news”)
‘Create the newsitem element
Set objNews = objXML.createElement(“newsitem”)
‘now we will create all the child elements in this case
‘title , link and description
objNews.appendChild objXML.createElement(“title”)
objNews.appendChild objXML.createElement(“link”)
objNews.appendChild objXML.createElement(“description”)
‘now we add values to the child elements
objNews.childNodes(0).text = “programmingsite.co.uk”
objNews.childNodes(1).text = “http://www.programmingsite.co.uk”
objNews.childNodes(2).text = “programming resources”
‘add the newsitem element to the news element
objXML.documentElement.appendChild objNews.cloneNode(true)
‘write the document using the xml method of the DOM
Response.Write objXML.xml
%>

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBibSonomyDeliciousDiggDiigoSina WeiboWordPressBlogger PostShare