Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27508

XML Reader Group box attributes

$
0
0
Evening all, I'm new round here :wave: and on the hunt for a friendly VB forum, I've posted the below else where and help has not been forthcoming. I'm hoping you'll be able to point me in the right direction?

I'm having trouble reloading a form previously saved to XML, the program throws an NullReferenceException ("object reference not set to an instance of an object") when it gets to line 16 in the below XML file, I'm certain its related to the group box child controls and its not reading them for some reason, but cant quite put my finger on it?

Any help much appreciated.

Vb code to load the XML

Code:

  Private Sub LoadFormState(ByVal inFile As String)
        Dim cntrl As Control, bFormIsSet As Boolean

        Try
            __xtr = New XmlTextReader(inFile)
            bFormIsSet = False


            While __xtr.Read
                If __xtr.NodeType = XmlNodeType.Element Then
                    If Not bFormIsSet Then
                        'First (outer) element is the form
                        Me.Name = __xtr.GetAttribute("Name")
                        Me.Text = __xtr.GetAttribute("Text")
                        Me.Visible = __xtr.GetAttribute("Visible")
                        bFormIsSet = True

                    Else

                        'Set the rest of the controls
                        cntrl = Me.Controls(__xtr.GetAttribute("Name"))
                        cntrl.Text = __xtr.GetAttribute("Text")
                        cntrl.Visible = __xtr.GetAttribute("Visible")

                    End If
                End If
            End While

        Finally
            If Not __xtw Is Nothing Then If Not __xtr Is Nothing Then
            'Close the file
            __xtr.Close()

 
            __xtr = Nothing
            cntrl = Nothing
        End Try
    End Sub

XML File

Code:

  <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <WindowsApplication1.Form1 Name="Form1" Text="Form1" Visible="True">
  <System.Windows.Forms.Button Name="Loadfrm1" Text="Load" Visible="True" />
  <System.Windows.Forms.Button Name="Savefrm1" Text="Save" Visible="True" />
  <System.Windows.Forms.Button Name="Hxdltconfirm" Text="Delete" Visible="False" />
  <System.Windows.Forms.CheckBox Name="Hxdlt8" Text="" Visible="False" />
  <System.Windows.Forms.CheckBox Name="Hxdlt7" Text="" Visible="False" />
  <System.Windows.Forms.CheckBox Name="Hxdlt6" Text="" Visible="False" />
  <System.Windows.Forms.CheckBox Name="Hxdlt5" Text="" Visible="False" />
  <System.Windows.Forms.CheckBox Name="Hxdlt4" Text="" Visible="False" />
  <System.Windows.Forms.CheckBox Name="Hxdlt3" Text="" Visible="False" />
  <System.Windows.Forms.CheckBox Name="Hxdlt2" Text="" Visible="False" />
  <System.Windows.Forms.CheckBox Name="Hxdlt1" Text="" Visible="False" />
  <System.Windows.Forms.GroupBox Name="GroupBox8" Text="GroupBox8" Visible="True" />
- <System.Windows.Forms.GroupBox Name="Hx2" Text="GroupBox1" Visible="True">
  <System.Windows.Forms.Button Name="Gotoest2" Text="Go to Estimate" Visible="True" />
  <System.Windows.Forms.ComboBox Name="Type2" Text="" Visible="True" />
  <System.Windows.Forms.Label Name="Label7" Text="Type" Visible="True" />
  <System.Windows.Forms.Label Name="Label8" Text="Equipment Tag" Visible="True" />
  <System.Windows.Forms.TextBox Name="Tag2" Text="123" Visible="True" />
  <System.Windows.Forms.Label Name="Label9" Text="Description" Visible="True" />
  <System.Windows.Forms.TextBox Name="Dsc2" Text="123" Visible="True" />
  </System.Windows.Forms.GroupBox>
- <System.Windows.Forms.GroupBox Name="Hx8" Text="GroupBox1" Visible="False">
  <System.Windows.Forms.Button Name="Gotoest8" Text="Go to Estimate" Visible="False" />
  <System.Windows.Forms.ComboBox Name="Type8" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label26" Text="Type" Visible="False" />
  <System.Windows.Forms.Label Name="Label27" Text="Equipment Tag" Visible="False" />
  <System.Windows.Forms.TextBox Name="Tag8" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label28" Text="Description" Visible="False" />
  <System.Windows.Forms.TextBox Name="Dsc8" Text="" Visible="False" />
  </System.Windows.Forms.GroupBox>
- <System.Windows.Forms.GroupBox Name="Hx7" Text="GroupBox1" Visible="False">
  <System.Windows.Forms.Button Name="Gotoest7" Text="Go to Estimate" Visible="False" />
  <System.Windows.Forms.ComboBox Name="Type7" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label23" Text="Type" Visible="False" />
  <System.Windows.Forms.Label Name="Label24" Text="Equipment Tag" Visible="False" />
  <System.Windows.Forms.TextBox Name="Tag7" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label25" Text="Description" Visible="False" />
  <System.Windows.Forms.TextBox Name="Dsc7" Text="" Visible="False" />
  </System.Windows.Forms.GroupBox>
- <System.Windows.Forms.GroupBox Name="Hx6" Text="GroupBox1" Visible="False">
  <System.Windows.Forms.Button Name="Gotoest6" Text="Go to Estimate" Visible="False" />
  <System.Windows.Forms.ComboBox Name="Type6" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label20" Text="Type" Visible="False" />
  <System.Windows.Forms.Label Name="Label21" Text="Equipment Tag" Visible="False" />
  <System.Windows.Forms.TextBox Name="Tag6" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label22" Text="Description" Visible="False" />
  <System.Windows.Forms.TextBox Name="Dsc6" Text="" Visible="False" />
  </System.Windows.Forms.GroupBox>
- <System.Windows.Forms.GroupBox Name="Hx5" Text="GroupBox1" Visible="False">
  <System.Windows.Forms.Button Name="Gotoest5" Text="Go to Estimate" Visible="False" />
  <System.Windows.Forms.ComboBox Name="Type5" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label16" Text="Type" Visible="False" />
  <System.Windows.Forms.Label Name="Label17" Text="Equipment Tag" Visible="False" />
  <System.Windows.Forms.TextBox Name="Tag5" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label18" Text="Description" Visible="False" />
  <System.Windows.Forms.TextBox Name="Dsc5" Text="" Visible="False" />
  </System.Windows.Forms.GroupBox>
- <System.Windows.Forms.GroupBox Name="Hx4" Text="GroupBox1" Visible="False">
  <System.Windows.Forms.Button Name="Gotoest4" Text="Go to Estimate" Visible="False" />
  <System.Windows.Forms.ComboBox Name="Type4" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label13" Text="Type" Visible="False" />
  <System.Windows.Forms.Label Name="Label14" Text="Equipment Tag" Visible="False" />
  <System.Windows.Forms.TextBox Name="Tag4" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label15" Text="Description" Visible="False" />
  <System.Windows.Forms.TextBox Name="Dsc4" Text="" Visible="False" />
  </System.Windows.Forms.GroupBox>
- <System.Windows.Forms.GroupBox Name="Hx3" Text="GroupBox1" Visible="False">
  <System.Windows.Forms.Button Name="Gotoest3" Text="Go to Estimate" Visible="False" />
  <System.Windows.Forms.ComboBox Name="Type3" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label10" Text="Type" Visible="False" />
  <System.Windows.Forms.Label Name="Label11" Text="Equipment Tag" Visible="False" />
  <System.Windows.Forms.TextBox Name="Tag3" Text="" Visible="False" />
  <System.Windows.Forms.Label Name="Label12" Text="Description" Visible="False" />
  <System.Windows.Forms.TextBox Name="Dsc3" Text="" Visible="False" />
  </System.Windows.Forms.GroupBox>
  <System.Windows.Forms.Button Name="Button3" Text="Delete" Visible="True" />
  <System.Windows.Forms.Button Name="Button2" Text="Ok" Visible="True" />
  <System.Windows.Forms.TextBox Name="Nohx" Text="2" Visible="True" />
  <System.Windows.Forms.Label Name="Label19" Text="# of tags" Visible="True" />
- <System.Windows.Forms.GroupBox Name="Hx1" Text="GroupBox1" Visible="True">
  <System.Windows.Forms.Button Name="Gotoest1" Text="Go to Estimate" Visible="True" />
  <System.Windows.Forms.ComboBox Name="Type1" Text="" Visible="True" />
  <System.Windows.Forms.Label Name="Label6" Text="Type" Visible="True" />
  <System.Windows.Forms.Label Name="Label5" Text="Equipment Tag" Visible="True" />
  <System.Windows.Forms.TextBox Name="Tag1" Text="123" Visible="True" />
  <System.Windows.Forms.Label Name="Label4" Text="Description" Visible="True" />
  <System.Windows.Forms.TextBox Name="Dsc1" Text="123" Visible="True" />
  </System.Windows.Forms.GroupBox>
  <System.Windows.Forms.Label Name="Label3" Text="Project" Visible="True" />
  <System.Windows.Forms.TextBox Name="Project" Text="123" Visible="True" />
  <System.Windows.Forms.Label Name="Label2" Text="TN Number" Visible="True" />
  <System.Windows.Forms.TextBox Name="TNnum" Text="123" Visible="True" />
  <System.Windows.Forms.Button Name="Button1" Text="Button1" Visible="True" />
  <System.Windows.Forms.Label Name="Label1" Text="Customer Name" Visible="True" />
  <System.Windows.Forms.TextBox Name="Cstname" Text="123" Visible="True" />
  </WindowsApplication1.Form1>


Viewing all articles
Browse latest Browse all 27508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>