Parse error?

Troy

Well-known member
Joined
Feb 7, 2005
Messages
153
Programming Experience
10+
I'm writing a configuration XML file and I'm setting these fields to save my information. My problem is I get an error. String was not recognised as valid Boolean.

VB.NET:
[/B]
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] WriteconfigValues()
ConfigOpt.SetOption([/SIZE][SIZE=2][COLOR=#a31515]"DBPath"[/COLOR][/SIZE][SIZE=2], TempPath)
ConfigOpt.SetOption([/SIZE][SIZE=2][COLOR=#a31515]"ALLUD"[/COLOR][/SIZE][SIZE=2], cbALLUD.Checked.ToString())
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] ReadConfigValues()
TempPath = ConfigOpt.GetOption([/SIZE][SIZE=2][COLOR=#a31515]"DBPath"[/COLOR][/SIZE][SIZE=2])
cbALLUD.Checked = [/SIZE][SIZE=2][COLOR=#0000ff]Boolean[/COLOR][/SIZE][SIZE=2].Parse(ConfigOpt.GetOption([/SIZE][SIZE=2][COLOR=#a31515]"ALLUD"[/COLOR][/SIZE][SIZE=2]))[/SIZE]
[SIZE=2]
[/SIZE]

The error occurs in the cbALLUD.checked statement.

The writeconfig saves the checked state as a string and the Boolean.Parse is supposed to convert the string back into a state for my checkbox.


 
For example this code works:
VB.NET:
Dim cb As New CheckBox
Dim b As Boolean = Boolean.Parse(cb.Checked.ToString())
 
Erm.. Quick question..

Why dont you just bind the cbALLUD.Checked property to the application settings, and then Save() the settings on exit?

i.e. Microsoft already wrote all the hard code for you to save the visual components' state to an XML file upon your demand; why would you reinvent their perfectly good wheel?
 
cjard,
Ok I'm not following what your saying could you give me an example?
 
Getting real advanced here cjard, video step-through and everything... :) You can also checkbox to save settings, see screenshot.
 

Attachments

  • settings.jpg
    settings.jpg
    68.3 KB · Views: 33
*bows to the masters* Oh you so rock.... lol
 
cJard make a 2005 training cd I'll buy it :D
 
Back
Top