Usage of My.Settings Error  
Author Message
LaserMan





PostPosted: Visual Basic General, Usage of My.Settings Error Top

I am trying to use the settings page to save user changeable options and when I try to read in anything from the settings I get the following error.

Reference to a non-shared member requires an object reference.

Example: Me.textbox.text = My.Settings.Servername

Thanks...




Visual Basic18  
 
 
Ken Tucker





PostPosted: Visual Basic General, Usage of My.Settings Error Top

I doubt the textbox's name is textbox. It probably should be

me.Textbox1.text = My.Settings.ServerName



 
 
LaserMan





PostPosted: Visual Basic General, Usage of My.Settings Error Top

That was just an example and it was late when I posted this question so I apologize for the typo. Any time anywhere in the app I try to reference the My.Settings.SomeValidName I get

Reference to a non-shared member requires an object reference. I am missing something; do I need to make a declaration or Imports statement

Example in FormLoad:

Private Sub ePref_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.txtMailServer.text = My.Settings.EmailServer

End Sub



 
 
spotty





PostPosted: Visual Basic General, Usage of My.Settings Error Top

You dont need to do anything except set up a setting in

My Project -> Setttings -> add a new setting call EmailServer which is of type string

And on form ensure there is a textbox control called txtmailserver.

Create a simple project with a single form and a setting and see if this works for you - it sounds like something has gotten screwed up on the project to me. This works fine for me.

The error is interesting as it occurs when you are trying to use a instance member as a Shared member, like in the following example. If you can find the exact line that is failing then you may be able to work back and see if something has gotten screwed up.

Module Module1

Sub Main
foo.x = 1 '<-- this will generate the error

'This will work
dim a as new foo
a.x = 1
End Sub
End Module

Class Foo
Public x As Integer
End Class


 
 
nobugz





PostPosted: Visual Basic General, Usage of My.Settings Error Top

Strange problem, sounds like something got hosed in the Settings Designer generated file. Take a look at it: click the Show All Files icon in the Solution Explorer, open "My Project", open Settings.settings and double-click Settings.Designer.vb

The relevant code in that file is:
Friend ReadOnly Property Settings() As Global.WindowsApplication1.My.MySettings
Get
Return Global.WindowsApplication1.My.MySettings.Default
End Get
End Property

Yours would use your project name rather than "WindowsApplication1". If you can't make heads nor tails of it, post the code you find in this file.


 
 
LaserMan





PostPosted: Visual Basic General, Usage of My.Settings Error Top

Thanks for the direction. I looked into the Settings.Designer.vb code and it was hosed. I tried to repair it to no avail so I deleted it, ran 'Rebuild' and then added my values back and wala! The code looks exactly like your example.

Thanks...