I am trying to save some boolean values from checkboxes using isolated
storage. I am able to do strings and integers without a problem but I
can't work out how to save boolean values without seeing the error
message below:
'Additional information: Argument 'Prompt' cannot be converted to type
'String'
The error message is displayed at this line of code in the form load
event.
'Dim isfs1 As IsolatedStorageFileStream = New
IsolatedStorageFileStream("frmGSCCServerConfig.xml ", FileMode.Open,
FileAccess.Read, isf)'
The full code listing is below:
Public Class frmGSCCServerConfigurationClass
Public EnableJobsIntegration, ForceFixes As Boolean
End Class
Imports System.IO
Imports System.IO.IsolatedStorage
Imports System.Xml
Imports System.Xml.Serialization
Public Class frmGSCCServerConfig
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSave.Click
Try
'get the isolated store for this assembly
Dim isf As IsolatedStorageFile =
IsolatedStorageFile.GetUserStoreForAssembly()
'create or truncate the settings file
'this will ensure that only the object we're
'saving right now will be in the file
Dim isfs1 As IsolatedStorageFileStream = New
IsolatedStorageFileStream("frmGSCCServerConfig.xml ", FileMode.Create,
FileAccess.Write, isf)
'Construct an object and tell it about the form
Dim fs As frmGSCCServerConfigurationClass = New
frmGSCCServerConfigurationClass
fs.EnableJobsIntegration =
Me.chkEnableJobsIntegration.Checked
fs.ForceFixes = Me.chkForceFixes.Checked
'serialize the object to the file
Dim xs As XmlSerializer = New
XmlSerializer(GetType(frmGSCCServerConfigurationCl ass))
xs.Serialize(isfs1, fs)
isfs1.Close()
Catch ex As Exception
MsgBox(ex)
'if setting can't be saved,next run will just use the
'form defaults
End Try
End Sub
Private Sub frmGSCCServerConfig_Load(ByVal sender As Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Try
'get the isolated store for this assembly
Dim isf As IsolatedStorageFile =
IsolatedStorageFile.GetUserStoreForAssembly()
'Open the settings file
Dim isfs1 As IsolatedStorageFileStream = New
IsolatedStorageFileStream("frmGSCCServerConfig.xml ", FileMode.Open,
FileAccess.Read, isf)
'Deserialize the XML to an object
Dim fs As frmGSCCServerConfigurationClass = New
frmGSCCServerConfigurationClass
Dim xtr As XmlTextReader = New XmlTextReader(isfs1)
Dim xs As XmlSerializer = New
XmlSerializer(GetType(frmGSCCServerConfigurationCl ass))
fs = CType(xs.Deserialize(xtr),
frmGSCCServerConfigurationClass)
'And apply the settings to the form
chkEnableJobsIntegration.Checked =
fs.EnableJobsIntegration.Equals(Boolean.TrueString )
chkForceFixes.Checked =
fs.ForceFixes.Equals(Boolean.TrueString)
'Clean up
isfs1.Close()
Catch ex As Exception
'no file found. Just run with the existing settings
MsgBox(ex)
End Try
End Sub
End Class
I'd be greatful for any suggestions.
Thank in advance
Robert