[Vb.net+xml] Complete Simple program configuration

Source: Internet
Author: User
xml| Program

Simple example of an application, just simple operation of the XML file, in the actual application can first build a configuration class save state.

Structure of the XML file:

1 <?xml version= "1.0" encoding= "Utf-8"?>
2 <config>
3 <function name= "a" checked= "false"/>
4 <function name= "B" checked= "false"/>
5 <function name= "C" checked= "false"/>
6 <function name= "D" checked= "false"/>
7 </config>

Specific program: Need a CheckedListBox, two button

1 public doc as New XmlDocument
2 Public RootNode as XmlElement
3 public strpathconfig as String = Application.startuppath & "\config.xml"
4 Public Intnum as Int16
5 Private Sub Button1_Click () Sub Button1_Click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Butt On1. Click
6 Writeconfig ()
7 End Sub
8 Private Sub Form1_Load () Sub Form1_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Mybase.loa D
9 ' Doing the prep work
Ten Doc. Load (Strpathconfig)
One rootnode = Doc. DocumentElement
Intnum = RootNode. Childnodes.count-1
13 '
Loadconfig ()
End Sub
16 ' Add to CheckedListBox
The function loadconfig () function Loadconfig ()
Dim I as Int16
For i = 0 to Intnum
CHECKEDLISTBOX1.ITEMS.ADD (RootNode. ChildNodes (i). Attributes (0). Value, CType (RootNode. ChildNodes (i). Attributes (1). Value, Boolean))
Next
End Function
23 ' OK, then write XML
function Writeconfig () function Writeconfig ()
Dim I as Int16
Dim Str as String
i = 0 to Intnum
RootNode. ChildNodes (i). Attributes (1). Value = checkedlistbox1.getitemchecked (i). Tostring
Next
Doc. Save (Strpathconfig)
End Function
32
The Private Sub Button2_Click () Sub Button2_Click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles But Ton2. Click
34 ' need to clear the items in CheckedListBox
CheckedListBox1.Items.Clear ()
Loadconfig ()
Notoginseng End Sub

End---


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.