I've got the basics of an XML ini file working. I.E. I can stash away
and retrieve user preferences. (Code below.) But how do I handle a
new preference? Say I have A and B. And then I invent C. The first
time the new version with C is run the XML file will not have a value
for C. How do I detect that case? Somewhere I got the impression
that I could use IsNull, but I was unable to find an example which I
could apply to my code. My attempt to use IsNull gives a runtime
error:
An unhandled exception of type 'System.MissingMemberException'
occurred in microsoft.visualbasic.dll
Additional information: Public member 'IsNull' on type 'String' not
found.
Here's my code (The runtine error happens in the btnLoad Sub).
Imports System
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Dim AppDir As String = Directory.GetCurrentDirectory()
#Region " Windows Form Designer generated code "
#End Region
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim ds As New DataSet("Settings") 'dataset
Dim dt As New DataTable("Textbox") 'table
dt.Columns.Add("xxx_filename", GetType(String)) 'add
columns
dt.Columns.Add("bbb_filename", GetType(String))
dt.Columns.Add("ignore_NOINS", GetType(Boolean))
dt.Columns.Add("log_filename", GetType(String))
dt.Rows.Add(dt.NewRow) 'add a row to table
ds.Tables.Add(dt) 'add table to the dataset
dt.Rows(0)("xxx_filename") = tbxXxxFile.Text 'set
values
dt.Rows(0)("bbb_filename") = tbxBbbFile.Text
dt.Rows(0)("ignore_NOINS") = chkbxIgnoreNOINS.Checked
dt.Rows(0)("log_filename") = tbxLogFile.Text
ds.WriteXml(AppDir & "\testxml.xml") 'write XML file
dt = Nothing
ds = Nothing
End Sub
Private Sub btnLoad_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnLoad.Click
Dim ds As New DataSet
Dim dt As DataTable
ds.ReadXml(AppDir & "\testxml.xml") '= ds.Tables(0)
If ds.Tables("Textbox").Rows(0)("xxx_filename").IsNul l Then
MsgBox("Whoops, xxx_filename IsNull")
End If
tbxXxxFile.Text = ds.Tables("Textbox").Rows(0)("xxx_filename")
tbxBbbFile.Text = ds.Tables("Textbox").Rows(0)("bbb_filename")
chkbxIgnoreNOINS.Checked =
ds.Tables("Textbox").Rows(0)("ignore_NOINS")
tbxLogFile.Text = ds.Tables("Textbox").Rows(0)("log_filename")
dt = Nothing
ds = Nothing
End Sub
End Class