import/export my.settings

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
I am trying to import/export my.settings. But encounter some error. I have this in a while loop reading the settings i have exported. And the settings are in (setting.Name,setting.PropertyValue.Tostring) format.

VB.NET:
Dim dataSplit = imput.Split(","c)
My.Settings(dataSplit(0))=dataSplit(1)

This seems to only work with string type settings. How do i make it work with all types? I tried this but gives error.

VB.NET:
Dim Type = My.Settings(dataSplit(0)).GetType()
My.Settings(dataSplit(0)) = CType(dataSplit(1), Type)
 
well in the first case, its an unhandled exception of type, cause its trying to put a string into a boolean type.

the 2nd case, give an error before compile, cant convert string into System.Type
 
CType requires that you specify a data type, not a Type object. They are very different things. The point of CType is to tell the compiler what type you are casting/converting to so you have to know yourself. It can't be something that's determined at run time. You might look at the Convert.ChangeType method. It's only going to work with inbuilt types but that's probably all you need it for.
 
Back
Top