asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search










Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Code Samples
Components
Tools
New
Free
Downloads
Vendors
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Persist Object

<script language="vbscript" runat=server>
class persist
	'***********************************************************************************
	'*** 04/12/02	TOM LANG	Persist  Object
	'***			vbscript wrapper class used to save form information
	'***********************************************************************************
	' ***	USER MANUAL
	'***********************************************************************************
	'set objPersist = new persist			'init object
	'objPersist.nameSpace = "myAppName"		'to prevent name collisions with other sub apps
	'objPersist.store name, value
	'value=objPersist.fetch name
	'set ovalue=objPersist.fetch oName		'gets an object
	'objPersist.clear name				'set value to empty string
	'objPersist.remove name				'removes name from collection
	'objPersist.removeAll				'removes all info from collection
	'set objPersist=nothing
	'***********************************************************************************
	'Note:  error handling is light due to the relative stability of working with session
	'variables.  Error handling should proBably be added if switching the data store 
	'to a file or dB.
	'***********************************************************************************

	'Private members
	private m_strErrorDescription
	private m_obj				'this obj will be persisted
	private m_strNameSpace			'namespace to prevent variable name collision
	
	'class initialization
	private sub class_initialize
		m_strNameSpace="pso_"		'default namespace
		m_strErrorDescription=""
	end sub
	
	private sub class_terminate
		'code to be run when obj is set to nothing
	end sub

	'Public interface
	public function store(key, value)
		'store information contained in parameter
		if isobject(value) then
			set session(m_strNameSpace & key)=value
		else
			session(m_strNameSpace & key)=value
		end if	
	end function

	public function fetch(key)
		'retreive info from data store (use instead of retrieve)
		if isobject(session(m_strNameSpace & key))=true then
			set fetch=session(m_strNameSpace & key)
		else
			fetch=session(m_strNameSpace & key)
		end if	
	end function

	public function retreive(key)
		'same as fetch.  kept to be compatible with previous vs.
		'NEW development should use fetch method
		if isobject(session(m_strNameSpace & key))=true then
			set retreive=session(m_strNameSpace & key)
		else
			retreive=session(m_strNameSpace & key)
		end if	
	end function

	public function removeAll()
		'removes all items from existence
		for each itm in session.Contents 
			if cStr(ucase(left(itm, len(m_strNameSpace))))=cStr(ucase(m_strNameSpace)) then
				if isobject(session(itm))=true then
					set session(itm)=nothing	'removes item from memory
				end if
				Session.Contents.Remove(itm)		'removes it from collection
			end if
		next
	end function

	public function remove(key)
		on error resume next
		if isobject(session(m_strNameSpace & key))=true then
			set session(m_strNameSpace & key)=nothing	'removes item from memory
		end if
		Session.Contents.Remove(cStr(m_strNameSpace & key))	'removes it from collection
		m_strNameSpace=Err.Description 
	end function

	public function clear(key)
		'set key to empty string
		if isobject(session(m_strNameSpace & key)) then
			set session(m_strNameSpace & key)=nothing
		end if
		session(m_strNameSpace & key)=""
	end function

	public property let nameSpace (strNameSpace)
		'prevent variable collisions by providing (sub)application name
		m_strNameSpace=strNameSpace
	end property

	public property get errorDescription
		'user friendly error message
		errorDescription = m_strErrorDescription
	end property

end class
</script>

Submitted by Tom Lang





email this code sample to a colleague


Support the Active Server Industry



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers