Here is the code from Microsoft's site --
<SCRIPT LANGUAGE="VBScript">
<!--
'****************************************************************
'Dimension and set the NOT_FOUND constant for the entire page
Dim NOT_FOUND
NOT_FOUND = "NOT_FOUND"
'****************************************************************
' Purpose: Creates or modifies the value assigned to a given
' variable.
' Inputs: strVariableName: The name of the variable that will
' have its value set.
' varVariableValue: The value that strVariableName
' should be set to.
' Returns: Nothing
' Notes: This function could be expanded to include other
' cookie attributes, such as expire date and valid
' domains. Cookies set with this implementation expire
' at the end of the user's session. If the cookie
' should remain valid for a longer period of time,
' an expires section can be added to the string. For
' example:
' ... & varVariableName & ";expires=01-Jul-96 GMT"
'****************************************************************
Sub SetVariable(strVariableName, varVariableValue)
Document.Cookie = strVariableName & "=" & varVariableValue
End Sub
'****************************************************************
' Purpose: Delete the variable with the name held in
' strVariableName
' Inputs: strVariableName: The name of the variable to delete
' Returns: Nothing
' Notes: The cookie is deleted by setting the expires attribute
' to a date that has already occurred. If one went back
' time, this method would break, so be sure to take that
' into account.
'****************************************************************
Sub KillVariable(strVariableName)
SetVariable strVariableName, "NULL;expires=Monday, 01-Jan-95 12:00:00 GMT"
End Sub
'****************************************************************
' Purpose: Finds and returns the value of of the variable with
' the name held in strVariableName
' Inputs: strVariableName: The name of the variable to return
' the value of.
' Returns: The value of the variable with the name of
' strVariableName.
' If the variable is not found, returns NOT_FOUND.
' Notes: This function could be greatly simplified if the
' bounds-checking code was removed.
' The NOT_FOUND constant should be set
' once for the entire page.
'****************************************************************
Function ReadVariable(strVariableName)
'these five variables are used in the string manipulation
'code that finds the variable in the cookie.
Dim intLocation
Dim intNameLength
Dim intValueLength
Dim intNextSemicolon
Dim strTemp
'calculate length and location of variable name
intNameLength = Len(strVariableName)
intLocation = Instr(Document.Cookie, strVariableName)
'check for existence of variable name
If intLocation = 0 Then
'variable not found, so it can't be read
ReadVariable = NOT_FOUND
Else
'get a smaller substring to work with
strTemp = Right(Document.Cookie, Len(Document.Cookie) - intLocation + 1)
'check to make sure we found the full string, not just a substring
If Mid(strTemp, intNameLength + 1, 1) <> "=" Then
'oops, only found substring, not good enough
ReadVariable = NOT_FOUND
'note that this will incorrectly give a not found result if and only if
'a search for a variable whose name is a substring of a preceding
'variable is undertaken. For example, this will fail:
'
'search for: MyVar
'cookie contains: MyVariable=2;MyVar=1
Else
'found full string
intNextSemicolon = Instr(strTemp, ";"
'if not found, then we need the last element of the cookie
If intNextSemicolon = 0 Then intNextSemicolon = Len(strTemp) + 1
'check for empty variable (Var1=

If intNextSemicolon = (intNameLength + 2) Then
'variable is empty
ReadVariable = ""
Else
'calculate value normally
intValueLength = intNextSemicolon - intNameLength - 2
ReadVariable = Mid(strTemp, intNameLength + 2, intValueLength)
End If
End If
End if
End Function
' ***********************************************
' Code behind buttons
' ***********************************************
Sub btnSaveVariable_onClick
Dim strVariableName
Dim varVariableValue
strVariableName = InputBox("Enter variable name"

varVariableValue = InputBox("Enter value for '" & strVariableName & "'"
SetVariable strVariableName, varVariableValue
End Sub
Sub btnReadVariable_onClick
Dim strVariableName
Dim varVariableValue
strVariableName = InputBox("Enter variable name to read"

varVariableValue = ReadVariable(strVariableName)
If varVariableValue = NOT_FOUND Then
MsgBox "'" & strVariableName & "' not found."
Else
MsgBox "'" & strVariableName & "' has a value of '" & varVariableValue & "'."
End If
End sub
Sub btnShowCookie_onClick
MsgBox Document.Cookie
End Sub
Sub btnNextPage_onClick
Location.HRef = "extcookie2.htm"
End Sub
Sub btnKillVariable_onClick
Dim strVariableName
Dim varVariableValue
strVariableName = InputBox("Enter variable name to delete"

varVariableValue = ReadVariable(strVariableName)
If varVariableValue = NOT_FOUND Then
MsgBox "'" & strVariableName & "' not found."
Else
KillVariable(strVariableName)
MsgBox "Variable deleted."
End If
End Sub
-->
</SCRIPT>