database - Alternative method to save data than my.settings for VB.Net -
i need save approximately 1600 different pieces of information windows forms application.
what best way go this? example of user settings measuringitem1name
, measuringitem1equation
, measuringitem1enabled
, measuringitem1offset
, measuringitem2name
...
i have looked my.settings, however, found tedious , error prone type out every user setting.
it seems best solution have type of table can access each individual cell , edit information.
does exist? if so, how implemented vb.net?
i'd recommend creating class properties hold settings. mark class serializable. serialize , deserialize instance of class application startup / shutdown user's profile directory. allow have typed settings save separately per user if ever need option. allow set default values settings.
you can make "settings" class deep want, properties made of other sub setting classes or lists of settings index. it's powerful pattern.
for example:
settings.measuringitem(1).enabled = true settings.measuringitem(1).equation = "1+1" settings.measuringitem(1).offset = 15 settings.measuringitem(2).enabled = true settings.measuringitem(2).equation = "1+1" settings.measuringitem(2).offset = 15
settings
main settings class generic.list(of measuringitem)
property on it. measuingitem
class .enabled boolean
, .equation string
, etc properties on it.
i haven't checked errors. want lot more safety checking, should started.
<serializable> public class settings public sub new() _measuringitems = new list(of measuringitem) end sub private _measuringitems list(of measuringitem) public readonly property measuringitems list(of measuringitem) return _measuringitems end end property public sub save() using s new io.filestream("path save", io.filemode.create) dim formatter new system.runtime.serialization.formatters.binary.binaryformatter formatter.serialize(s, me) end using end sub public shared function load() settings dim settings settings = nothing using s new io.filestream("path load", io.filemode.open) dim formatter new system.runtime.serialization.formatters.binary.binaryformatter settings = ctype(formatter.deserialize(s), serverhost.settings) end using return settings end function end class <serializable> public class measuringitem public property enabled boolean = true 'these default values public property equation string = "1+1" public property offset integer = 15 end class
a quick example of usage:
'create new settings instance 100 measuring items dim settings1 settings = new settings integer = 1 100 settings1.measuringitems.add(new measuringitem) next settings1.measuringitems(0).enabled = false settings1.measuringitems(5).equation = "testing" 'save settings1.save() 'load saved settings dim settings2 settings = settings.load
Comments
Post a Comment