473,624 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serialize global variables

Hello,

I have a settings class that looks like this:

Imports System.Xml.Seri alization
<Serializable() _
Public Class MySettings

<XmlAttributeAt tribute("ItemCa tegory")_
Public Shared ItemCategory As Integer

<XmlAttributeAt tribute("Defaul tItemCategoryID ")_
Public Shared DefaultItemCate goryID As Integer

Public Shared Sub LoadSettings()
ItemCategory = 1042
DefaultItemCate goryID = 1456
End Sub

End Class

As you probably guessed, when I serialize this object to XML, there are no
attributes or values in the XML, just the header and the object name. The
shared variables DO have values. Why is this and how can I serialize these
values?

TIA,

Monty
Feb 28 '07 #1
4 1310
Monty,

XML Serialization does not serialize shared properties/fields.

You could create public non-shared properties as wrappers for the shared
properties/fields.

Kerry Moorman
"Monty" wrote:
Hello,

I have a settings class that looks like this:

Imports System.Xml.Seri alization
<Serializable() _
Public Class MySettings

<XmlAttributeAt tribute("ItemCa tegory")_
Public Shared ItemCategory As Integer

<XmlAttributeAt tribute("Defaul tItemCategoryID ")_
Public Shared DefaultItemCate goryID As Integer

Public Shared Sub LoadSettings()
ItemCategory = 1042
DefaultItemCate goryID = 1456
End Sub

End Class

As you probably guessed, when I serialize this object to XML, there are no
attributes or values in the XML, just the header and the object name. The
shared variables DO have values. Why is this and how can I serialize these
values?

TIA,

Monty
Feb 28 '07 #2
After several experiments with your code I can confirm that it will not take
values. I guess the question is what you are trying to accomplish.

How many instances of this object type do you expect? If only one then you
read it at application startup and either write it each time it changes or
when the application closes. In that case you should not need shared
variables but perhaps a set of module properties which can then return the
values to the application.

Lloyd Sheen
"Monty" <mo***@communit y.nospamwrote in message
news:OI******** ******@TK2MSFTN GP05.phx.gbl...
Hello,

I have a settings class that looks like this:

Imports System.Xml.Seri alization
<Serializable() _
Public Class MySettings

<XmlAttributeAt tribute("ItemCa tegory")_
Public Shared ItemCategory As Integer

<XmlAttributeAt tribute("Defaul tItemCategoryID ")_
Public Shared DefaultItemCate goryID As Integer

Public Shared Sub LoadSettings()
ItemCategory = 1042
DefaultItemCate goryID = 1456
End Sub

End Class

As you probably guessed, when I serialize this object to XML, there are no
attributes or values in the XML, just the header and the object name. The
shared variables DO have values. Why is this and how can I serialize these
values?

TIA,

Monty

Feb 28 '07 #3
Hi Lloyd,

Thanks for trying with my code. I won't have any instances of the object
and will be referencing it's shared values from the far reaches of my web
application. I much prefer to just do something like

X = MySettings.Item Category

Than something like

dim o as MySettings = ctype(applicati on("MySettings" ), MySettings)
X = o.ItemCategory

I'd love to just serialize/deserialize this object to save it in a
textstream.

Monty
Feb 28 '07 #4
Might have to do that, tedious as it is. Thanks Kerry.

Monty
Feb 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
24171
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); function loadUrlVariables() { varString = location.search;
7
5822
by: Ian Tompsett | last post by:
H I was wondering if it possible for an object to serialize/deserialize itself from XML. I'd be guessing that it would need to use the XmlSerializer class, but that seems to want to create a brand new object when deserializing. In my case I have an existing object that I'd like to pass some XML to for the object to repopulate its member variables. Similarly I'd like it to be able to populate an XML string from the values of its member...
17
5612
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm constantly running tests on imperfect code. On of the cumbersome jobs encountered is reassigning global vars their values after a close encounter with an untrapped runtime error. Rather than writing a procedure to simply reassign them all with a...
33
3032
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have been for years. If the machine has memory to spare and windows can use it - I'm thinking "Why not?" I was wondering what some of you have to say about that, particularly any severe "gotchas" you've had the unfortunate experience to contend with.
5
24695
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream s); public void Deserialize(Stream s); Within the MyUserControl class, there is a field of type MyInnerClass
9
8642
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang Su Gatlin, casual mention was made about using static variables as an alternative to using global variables. This caused me to think of the following: '-----Begin module code
5
11811
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global $MYVAR, $a; ?>
1
29338
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this condition. The opinions expressed in this article are those of the author alone although many have...
112
5416
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions that may print some messages. foo(...) { if (!silent)
0
8238
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8624
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1485
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.