Home All Groups Group Topic Archive Search About

My.Settings object set setting by name?

Author
6 May 2006 2:35 AM
Dachshund Digital
I know there must be a way to do this... in .NET 2.0?

I have a situation where I know the name of the setting, and want to
pass it into a function, and set or get the corresponding setting.

The following is find, but a pain if you have lots of settings to do in
one go...

My.Setting.Dachshund=1000
Dim theSetting As Integer=My.Setting.Dachshund

Looking for some thing like...

Sub SetSetting(ByVal theName As String, ByVal theValue As Object)

  My.Setting(theName) = theValue

End Sub

Function GetSetting(ByVal theName As String) As Object

  Return (My.Settings(theName))

End Function

I figure i could call My.Setting.<Method>?  Via Invoke by name?  But I
am not a Invoke guru?

Any help greatly desired, Thanks

Author
8 May 2006 9:03 AM
david
On 2006-05-06, Dachshund Digital <Schors***@adelphia.net> wrote:
Show quoteHide quote
> I know there must be a way to do this... in .NET 2.0?
>
> I have a situation where I know the name of the setting, and want to
> pass it into a function, and set or get the corresponding setting.
>
> The following is find, but a pain if you have lots of settings to do in
> one go...
>
> My.Setting.Dachshund=1000
> Dim theSetting As Integer=My.Setting.Dachshund
>
> Looking for some thing like...
>
> Sub SetSetting(ByVal theName As String, ByVal theValue As Object)
>
>   My.Setting(theName) = theValue

This is evil, but you could always do something like

My.MySettingsProperty.Settings.Item(theName) = value


Rather than using undocumented names though, you'd probably be better
off saving a hashtable or NameValueCollection in My.Settings, then
accessing its members normally.



Show quoteHide quote
>
> End Sub
>
> Function GetSetting(ByVal theName As String) As Object
>
>   Return (My.Settings(theName))
>
> End Function
>
> I figure i could call My.Setting.<Method>?  Via Invoke by name?  But I
> am not a Invoke guru?
>
> Any help greatly desired, Thanks
>