"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message news:<#M******* *******@TK2MSFT NGP09.phx.gbl>. ..
"Sandy Murdock" <sa***@murdocks .on.ca> schrieb:I am not clear on where or how to use:
Simply use 'CurrentUser.Ge tInstance().Nam e = "Bla"'.
I have tried a few places and modifications but none seems to be a valid
command. Is that a C# style command?
Sorry for the other messages -- my keyboard temporarily didn't work for some
reasons.
You can use the code above everywhere in your code after you added the
Singleton class to your project. '.Name = "Bla"' is only a sample that
presumes that you have added a 'Name' property to the 'CurrentUser' class.
I have been away from this program for some time (surgery, nothing
life threatening but I have been off work.) so I have now done the
following:
Created the class as outlined:
Public NotInheritable Class Settings
Private Shared m_DefInstance As Settings
Dim m_UserName As String
Private Sub New()
'
End Sub
Public Shared Function GetInstance() As Settings
If m_DefInstance Is Nothing Then
m_DefInstance = New Settings
End If
Return m_DefInstance
End Function
Public Property UserName() As String
Get
Return m_UserName
End Get
Set(ByVal Value As String)
m_UserName = Value
End Set
End Property
End Class
Then in my program I do this:
Sub SetFormToUser(B yVal objUser As User)
Dim objThisUser As Settings
objThisUser.Get Instance()
MessageBox.Show (objUser.FirstN ame)
objThisUser.Use rName = objUser.FirstNa me
Me.UserID = objUser.UserID
Me.UserPwd = objUser.Pwd
Me.FirstName = objUser.FirstNa me
Me.LastName = objUser.LastNam e
Me.UserTypeID = objUser.UserTyp eID
Me.UserType = objUser.UserTyp e
End Sub
This code is on the actual login form. I set the properties for the
form (which ultimately I hope to do away with) and, in theory, set the
the UserName property from the Settings Class (called objThis user).
Here is the problem;
I can confirm that objUser.FirstNa me has a value, but when I try to
run the code I get an error: "Object reference not set to an instance
of an object."
I believe this is caused by the objThisUser (Settings) object,
UserName property not existing? There is some strange thing happening
here; I know that I am assigning a value, but I am getting the 'Null'
message.
Do you have any idea what might cause that?