123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home

Source Codes

Engineering Colleges

BE Students

Training  Reports (updated)

Seminar Reports (updated

Placement Papers (updated)

Forums

   Computer Science / IT

   Electronics

   Electrical

   Mechanical

   Chemical

   Civil

   CAT / MBA

   GMAT / Foreign MBA

Latest Jobs

Engineering Jobs / Technical Jobs

Management Jobs

Sitemap

About-Us

Terms of use

Displaying  Source Code(s)  
 

 
VBScript Cookie/Counter

--------------------------------------------------------------------------------

Description : Not only does this sample show you how to create a counter, but more impotantly, it shows you how to create a cookie, which in todays world is a MUST HAVE tool. Cookies are anywhere and everywhere, they can store all kinds of information too, all you have to do is add an extra line (textline/field) in the file for each piece of information that you wish to persist.

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document
STEP 1
Be sure To enclose the code below In SCRIPT tags, both start And End are required.
'The name of the subroutine
Sub CookieActions
'declare the constants which we will use
'
Const ForReading=1, ForWriting=2, TristateFalse=0
'declare the local variables which we wi
' ll use
'fso = the file scripting object
'MyFile = the file where we will persist
' our data
'MyStream = the textstream object we wil
' l use to access the file
'MyTitle = on of our data fields - the t
' itle of the page
'MyData = another of our fields - the da
' ta in question, in this case a counter
Dim fso, MyFile, MyStream, MyTitle, MyData, MyVisits
'initialise/create the file scripting ob
' ject
Set fso=CreateObject("Scripting.FileSystemObject")
'test to see if our file already exists
'Note:
'Our file is zaf@drzed-VbsCountaDemoHtm.
' txt, and is in c:windowscookies
If (fso.FileExists("c:windowscookieszaf@drzed-vbscountademohtm.txt")) Then
'it does exist, so we will get the file
Set MyFile = fso.GetFile("c:windowscookieszaf@drzed-vbscountademohtm.txt")
'open the textstream object for reading
Set MyStream = MyFile.OpenAsTextStream(ForReading)
'read the first line and assign it to ou
' r title variable
MyTitle = MyStream.ReadLine
'read the second line and assign it to o
' ur data variable
MyData = Mystream.ReadLine
'close the textstream object, and file a
' ll in one go
MyStream.Close
'extract our data from the data string,
' by only excluding the first 7 characters
' , (thats 'VISITS=')
MyVisits = Right(MyData,Len(MyData)-7)
'increment the counter, to include this
' visit
MyVisits = MyVisits + 1
'display message box, to show the inform
' ation
MsgBox "Title: " & MyTitle & vbCrLf & "Visits: " & MyVisits & vbCrLf & "http://home.clara.net/doczaf/index.html",,"Dr Zed Productions."
'get the file ready, so that we can writ
' e out the updated data
Set MyFile = fso.GetFile("c:windowscookieszaf@drzed-vbscountademohtm.txt")
're-open the textstream, this time for w
' riting
Set MyStream = MyFile.OpenAsTextStream(ForWriting, TristateFalse)
'write out the first line, the page titl
' e
MyStream.WriteLine "Splash Screen Counter"
'write out the last line, the updated co
' unter value, prefixed with the text 'VIS
' ITS='
MyStream.WriteLine "Visits=" & MyVisits
'close the textstream and file, all in o
' ne go
MyStream.Close
Else
'the file does not exist, so create it b
' y opening it
Set myfile = fso.CreateTextFile("c:windowscookieszaf@drzed-vbscountademohtm.txt", True)
'write out the first line, the page titl
' e
MyFile.WriteLine("Splash Screen Counter")
'write out the last line, the initial co
' unter value, prefixed with the text 'VIS
' ITS='
MyFile.WriteLine("Visits=1")
'close the file
MyFile.Close
'display message box, to show the inform
' ation
MsgBox "Welcome To My Site" & vbCrLf &" Visits: 1"& "http://home.clara.net/doczaf/index.html", ,"Dr Zed Productions."
End If
End Sub
STEP 2
Be sure To include the following Text In your BODY tag
ONLOAD="CookieActions"
FURTHER INFO
Not only does this sample show you how To create a counter, but more impotantly, it shows you how To create a cookie, which In todays world Is a MUST HAVE tool.
Cookies are anywhere And everywhere, they can store all kinds of information too, all you have To Do Is add an extra line (textline/field) In the file For Each piece of information that you wish To persist.

DocZaf
Enjoy

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved copyright 123ENG