473,499 Members | 1,747 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.Serialization
<Serializable()_
Public Class MySettings

<XmlAttributeAttribute("ItemCategory")_
Public Shared ItemCategory As Integer

<XmlAttributeAttribute("DefaultItemCategoryID")_
Public Shared DefaultItemCategoryID As Integer

Public Shared Sub LoadSettings()
ItemCategory = 1042
DefaultItemCategoryID = 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 1307
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.Serialization
<Serializable()_
Public Class MySettings

<XmlAttributeAttribute("ItemCategory")_
Public Shared ItemCategory As Integer

<XmlAttributeAttribute("DefaultItemCategoryID")_
Public Shared DefaultItemCategoryID As Integer

Public Shared Sub LoadSettings()
ItemCategory = 1042
DefaultItemCategoryID = 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***@community.nospamwrote in message
news:OI**************@TK2MSFTNGP05.phx.gbl...
Hello,

I have a settings class that looks like this:

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

<XmlAttributeAttribute("ItemCategory")_
Public Shared ItemCategory As Integer

<XmlAttributeAttribute("DefaultItemCategoryID")_
Public Shared DefaultItemCategoryID As Integer

Public Shared Sub LoadSettings()
ItemCategory = 1042
DefaultItemCategoryID = 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.ItemCategory

Than something like

dim o as MySettings = ctype(application("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
24156
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(); ...
7
5805
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...
17
5591
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...
33
2987
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...
5
24657
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...
9
8610
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...
5
11796
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...
1
29301
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...
112
5344
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...
0
7225
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...
1
6901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7392
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4920
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...
0
4605
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...
0
3105
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...
0
1429
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 ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.