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

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Wrapping FileSystemWatcher to prevent crossthread ops
    ... Public Shadows Event Changed(ByVal sender As Object, ... Private Delegate Sub DelegatorFSE(ByVal sender As Object, ... Private Sub watch_Changed(ByVal sender As Object, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Events - weiterreichen
    ... Private Sub Button5_Click(ByVal sender As System.Object, ... ByVal e As System.EventArgs) Handles Button5.Click ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Displaying calendar month according to Datalist choice
    ... Private Sub Page_Load(ByVal sender As System.Object, ... Dim dtNewDate As DateTime ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Was bedeutet Paralellitätsverletzung?
    ... Private Sub goFrmSpracheVerwalten_Load(ByVal sender As ... ByVal e As System.EventArgs) Handles MyBase.Load ... Private Sub cmdSchliessen_Click(ByVal sender As System.Object, ...
    (microsoft.public.de.german.entwickler.dotnet.datenbank)
  • Re: intermec multiple barcode read events
    ... private void TransporterForm_Deactivate(object sender, EventArgs e) ... > Form2 has it's own instance of a barcode reader object. ... > Public Sub New ... > Private Sub Form1_Load(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.compactframework)