dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB6
Expertise: Advanced
Nov 25, 2003

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Serialize Data Using a PropertyBag

You can serialize your data quickly by placing it into a PropertyBag object, then reading the PropertyBags Contents property. This property is really a Byte array that is a serial representation of the data in your PropertyBag object. You can use this byte array for many purposes, including an efficient means of data transmission over DCOM:

Private Function PackData() As String
	Dim pbTemp	As PropertyBag
	
	'Create a new PropertyBag object
	Set pbTemp = New PropertyBag
	With pbTemp
		'Add your data to the PB giving each item a 
		'unique string key
		Call .WriteProperty("FirstName", "John")
		Call .WriteProperty("MiddleInitial", "J")
		Call .WriteProperty("LastName", "Doe")
		
		'Place the serialized data into a string 
		'variable.
		Let PackData = .Contents
	End With
	
	Set pbTemp = Nothing
End Function
To retrieve the serialized data, simply create a new PropertyBag object and set the serialized string to its Contents property. Convert the string into a byte array before assigning it to the Contents property:

Private Sub UnPackData(sData As String)
	Dim pbTemp	As PropertyBag
	Dim arData()	As Byte
	
	'Convert the string representation of the data to 
	'a Byte array
	Let arData() = sData
	
	'Create a new PropertyBag object
	Set pbTemp = New PropertyBag
	With pbTemp
		'Load the PropertyBag with data
		Let .Contents = arData()
		
		'Retrieve your data using the unique key
		Let m_sFirstName = .ReadProperty("FirstName")
		Let m_sMiddleInitial = _
			.ReadProperty("MiddleInitial")
		Let m_sLastName = .ReadProperty("LastName")
	End With
	 
	Set pbTemp = Nothing
End Sub
Mike Kurtz, McKees Rocks, Pa.
Mike Kurtz
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date