Categories

Subscribe via Email

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

Text Counter

Now create a folder called counters or you can call it something else if you want just remember and change the code above . Now create a text file called counter1.txt and enter whatever you wish to start the count at.

<%@ Language=VBScript %>
<%
Dim fso
Set fso = Server.CreateObject(“Scripting.FileSystemObject”)
//this is the path to your counter1.txt file
counter = Server.MapPath(“/counters”) & “\counter1.txt”
//open the text file
Set InStream = fso.OpenTextFile(counter , 1, False)
oldCount = Trim(InStream.ReadLine)
//increment the oldcount by 1 and store in newcount
newCount = oldCount + 1
Set OutStream = fso.CreateTextFile(counter, True)
//copy newcount to the text file
OutStream.WriteLine(newCount)
%>

Now you would place the folllowing where you want the counter to appear on your site

<%= newCount%>

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

Display a CSV file

Display a CSV file

CSV files are common formats to get information . I have seen commission sites , stock quotes and various links in these types of files . CSV are comma seperated value files , the typical format of one of these could be like this.

1000,age,234,billy

This is not much to look at but with a little scripting we can make it more readable . In this example we have a stock quotes csv file downloaded from Yahoo which we wish to display.
<%

‘declare our variables
Dim objFSO , strURL , objFile
‘create an instance of the file system object
Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)
‘this is the csv file downloaded from yahoo
strURL = Server.MapPath(“quotes.csv”)
‘open the file
Set objFile = objFSO.OpenTextFile(strURL)
‘while we are not at the end of the file
Do While Not objFile.AtEndOfStream
‘store the contents of the file in strText
strText = objFile.readLine
‘split the strText
arrText = split(strText, “,”, 9)
Loop
‘close and destroy objects
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
%>

<table>

<tr><td>description</td><td>latest figure</td><tr>

<tr><td>symbol</td><td><%= arrText(0) %></td></tr>

<tr><td>last price</td><td><%= arrText(1) %></td></tr>

<tr><td>date</td><td><%= arrText(2) %></td></tr>

<tr><td>time</td><td><%= arrText(3) %></td></tr>

<tr><td>change</td><td><%= arrText(4) %></td></tr>

<tr><td>open</td><td><%= arrText(5) %></td></tr>

<tr><td>high</td><td><%= arrText(6) %></td></tr>

<tr><td>low</td><td><%= arrText(7) %></td></tr>

<tr><td>volume</td><td><%= arrText(8) %></td></tr>

</table>

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBibSonomyDeliciousDiggDiigoSina WeiboWordPressBlogger PostShare