public shared object... and disappearing xml content in file

R

Roger

I have two issues that I want to deal with...

I am new to windows programming (I usually do web...)

I want to create a class which, is instantiated and then available to all
forms. I assume this is public shared... (similar to Java). I also assume I
have to instantiate it BEFORE the first form unless I want all other forms
to have to call it by form1.obj.... (which I don't).

How can I create a 'main' or some such, that will be executed before the
vb.net form1? Can I then just dimension my object as : Public Shared {name}
as new {class name}.

******
Second, I intend this object to have in it a dataset which is globally
available. It is created from an xml file stored on disk.

Currently I instantiate my public shared item from form 1. In the 'new' sub
of the class I have a readxml command to read the xml file into a dataset
belonging to my object. When form1 is closed, I write the XML to the drive.

Currently I can write the xml correctly, but as soon as I re-start the
application the xml file gets over-written as a blank xml file. (I don't
like that and don't want that...)

Here is what the code looks like:

My public shared object is called AppValues

Public Class AppValues
Public Shared ds As New WhatsRunning 'WhatsRunning is a xsd file
Public Sub New()
Try
ds.ReadXml("WhatsRunning.xml")
Catch ex As Exception
End Try
If ds.Tables("WebPages") Is Nothing Then
Dim dt1 As New WhatsRunning.WebPagesDataTable
ds.Tables.Add(dt1)
End If
End Sub
End Class

From Form 1 I have snipped the following:

Public Class Form1
Public Shared AV As New AppValues

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
<snip - this is code that I use to get the data and insert values into
a row in the 'WebPages" table of AppValues.ds it works fine
End Sub

Private Sub Form1_Close(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Disposed
AV.ds.WriteXml("WhatsRunning.xml") 'This code is used to write the
XML when the form closes. It works fine.
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
<snip This sub doesn't impact because the xml file is overritten before
anyone can press the button>

End Sub

End Class
 
R

Roger

I have figured out PART of this. I can't call my xml file WhatsRunning.xml

Don't know why, but changing the name to WhatsRunning1.xml fixed the
overwriting (blanking) of the xml file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top