user.settings question

thirteentwenty

Well-known member
Joined
Oct 9, 2008
Messages
80
Location
Honolulu
Programming Experience
Beginner
Hey all, it's me again...
and again I'm not sure if this is the correct place for this, please move if needed, thank you.

I've got what seems to be a basic question concerning user.settings.

What would be the preferred way of calling it

something like

VB.NET:
Me.txt_someTextBox.Text = My.Settings.strSomething

or

VB.NET:
Me.txt_someTextBox.Text = My.Settings.Item("strSomething").ToString

I've seen it done both ways in my meanderings on how this is used. But now I'm a bit confused about it, has one way been depreciated? Or is one way just "wrong"... what are your practices regarding its use?

Thanks again!
 
Was that "strSomething" or "stringSomething" again? My.Settings.strSomething doesn't have that problem.
 
I would sometimes use the .Item alternative because you can then load a certain setting from a variable e.g. pseudo:

VB.NET:
Dim SettingName as String = InputBox("Which setting?")
Dim SettingValue as String = My.Settings.Item(SettingName).ToString
Msgbox(SettingName + " is " + SettingValue)
 
Always, always, always prefer the strongly typed My.Settings.SettingName over the weakly typed My.Settings("SettingName")


My.Settings.SettingName <-- this is how we get the compiler to catch bugs at design time
My.Settings("SettingName") <-- this is how we cause obscure, hard-to-trace bugs
 
Ahh thank you for the clarification.
 
Back
Top